Forum Moderators: phranque
I've just moved a site to a different host, and I'm having a maddening problem getting a rewrite to work - not helped by the fact I seem to have forgotten some of the basics.
In the .htaccess in the root directory I have the following to rewrite reuests for domain.co.uk to www.domain.co.uk:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.co\.uk [NC]
RewriteRule ^(.*)$ [domain.co.uk...] [R=permanent,L]
This works fine, including for all pages in subdirectories except for one, which contains a rewrite to direct netscape browsers to another page. So, in /directory/ I have:
rewriteOptions inherit
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} Mozilla.* [NC]
RewriteCond %{HTTP_USER_AGENT} .*netscape.* [NC]
RewriteRule page.html /directory/page_ns.html [R,L]
The problem is that a request for domain.co.uk/directory/page.html comes out as www.domain.co.uk/page_ns.html generating a 404 error
It seems it is partially rewriting the request, but losing the directory somewhere in the process. I'm having trouble seeing why the backreference isnt containing the whole path.
I'm fairly sure this worked OK on the old host, but its possible I may not have tested this URL for the domain.co.uk to www.domain.co.uk rewrite.
I'm confident I am being a little thick and missing the obvious - any help appreciated.
RewriteRule ^page\.html$ http://www.domain.co.uk/directory/page_ns.html [R=301,L]
You could simply do an internal rewrite to provide alternate content at the same URL for NS users:
RewriteRule ^page\.html$ /directory/page_ns.html [L]
Jim