Forum Moderators: phranque
Essentially, the behaviour I am trying to get is:
1. Resubmit URL (after site rebranding), adding a trailing slash if there is none.
2. Have the URL request sent to a single .php file (technique outlined in http://www.alistapart.com/articles/succeed/)
RewriteEngine on
RewriteRule ^XYAZ/(.+[^/])$ /XYZ/$1/ [R]
This successfully maps http://www.myserver.com/XYAZ/events to http://www.myserver.com/XYZ/events/
RewriteEngine on
RewriteRule!\. (gif¦jpg¦css)$ xyz.php [L]
This successfully directs http://www.myserver.com/XYZ/events/ to xyz.php (which then dynamically serves the content based on the final element of the URL - hence the need for the trailing slash).
RewriteEngine on
RewriteRule ^XYAZ/(.+[^/])$ /XYZ/$1/ [R]
RewriteRule!\. (gif¦jpg¦css)$ xyz.php [L]
With this in .htaccess, http://www.myserver.com/XYAZ/events returns "400 Bad Request. Your browser sent a request that this server could not understand".
Any ideas how I can combine the two behaviours please?
Many thanks,
Nick.
[edited by: jdMorgan at 2:38 am (utc) on Jan. 8, 2004]
[edit reason] de-linked [/edit]
The following rewrites are done in stages so that they do not depend on each other - that is, missing slashes are added for directory requests in all domains, XYAZ.com is then redirected to XYZ.com, and finally the appropriate page requests are delivered to your xyz.php script - again, for all domains.
If you try to combine all these, then requests which *do* have a trailing slash, or those made directly to XYZ.com would not be delivered to your script. Image and CSS file requests made to XYAZ would not be redirected to XYZ.com... These are just examples of why the rewrites must be independent of each other.
RewriteEngine on
#
# IF URI does not end with "/"
RewriteCond %{REQUEST_URI} !/$
# and IF URI does not end with <anything> <dot> <something>
RewriteCond %{REQUEST_URI} ![^.]*\.[^.]+$
# THEN append trailing slash and redirect the client
RewriteCond %{HTTP_HOST} (.+)
RewriteRule (.*) http://%1/$1/ [R=301,L]
#
# Externally redirect XYAZ.com to XYZ.com
RewriteCond %{HTTP_HOST} ^(www\.)?XYAZ\.com
RewriteRule .* http://www.XYZ.com [R=301,L]
#
# Internally redirect all except image, CSS, and script requests to xyz.php
RewriteRule !(\.gif¦\.jpg¦\.css¦xyz\.php)$ /xyz.php [L]
If you have files whose names do not include a file type (extension), then you will have to use the -d and/or -f flags of RewriteCond to tell files and directories apart. Otherwise, the simple test for a dot in the filename shown above should work fine.
Change all the broken pipe characters back to solid pipes before use - posting here changes them.
Jim
What does not work? Which function is failing and how?
(Basically, what do you type, and then what do you see as a result?
(I should add that there may not be a solution, since you normally should not have to do anything about trailing slashes - that should be taken care of automatically, but isn't. This indicates a possible server set-up problem.)
Jim
[myserver.com...] - serves home page
[myserver.com...] - serves home page.
It seems that it's only happy serving root when a second trailing slash is appended. Any ideas?
Thanks for clearing up the XYAZ to XYZ translation.
Regards,
Nick
Serving local content, IE6 renders [localhost...] correctly as the home page, but Mozilla Firebird 0.7 doesn't (displays Test Page for Apache Installation). When the content is uploaded to the web, Firebird serves the root content fine.
Thanks for all your help.
Nick.