Lately I’ve being doing some work on a few websites. One company posed an interesting problem: they wanted to use their existing webhotel account to host two or three new sites.
I moved the existing files and folders in the root into a new subfolder and figured I’d do the same to the new sites. Sounds simple enough.
As always with this type of work, problems arise and this time was no exception. The forward to the new folder worked fine, but in typo3 – the CMS used on the existing site – some links with canonical urls weren’t working and instead forwarded to the index page.
After getting to know typo3 and spending some time debugging, I figured out it was links to pages with short titles that weren’t working and finally hunted down the problem to a typo3’s helper function. It seems typo3 uses the actual php file’s location on the server instead of the uri when getting the REQUEST_URI using the helper function. This is used when typo3’s canonical plugins extract the title and post number from the uri. A modification to the function fixed that.
The next problem I ran into was getting a 403 error when forwarding the new domain. This was due to a missing slash before the folder name.
Here’s my final .htaccess file:
RewriteEngine On
# NOTE: Also place all valid domain names as NOT (!) conditions in the last ruleset where unwanted requests are processed
# SITE 1
RewriteCond %{HTTP_HOST} ^domain1\.([a-z]+)$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain1\.([a-z]+)$
RewriteCond %{REQUEST_URI} !^/site1/
RewriteRule (.*) site1/$1 [L]
# SITE 2
RewriteCond %{HTTP_HOST} ^domain2\.([a-z]+)$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain2\.([a-z]+)$
RewriteCond %{REQUEST_URI} !^/site2/
RewriteRule (.*) site2/$1 [L]
#
# Place other domains before this line. This forwards unwanted requests to an empty directory
#
RewriteCond %{HTTP_HOST} !^domain1\.([a-z]+)$
RewriteCond %{HTTP_HOST} !^www\.domain1\.([a-z]+)$
RewriteCond %{HTTP_HOST} !^domain2\.([a-z]+)$
RewriteCond %{HTTP_HOST} !^www\.domain2\.([a-z]+)$
RewriteCond %{REQUEST_URI} !^/empty_do_not_move/
RewriteRule .* /empty_do_not_move/I found this article and used it to learn mod_rewrite: http://corz.org/serv/tricks/htaccess2.php along with the apache documentation: http://httpd.apache.org/docs/2.2/rewrite/



0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.