Forum Moderators: phranque
www.foo.com/about
to go to www.foo.com/xyz/about.php
However, I am getting www.foo.com//xyz/about.php which works but is annoying.
A problem is that all of the mod_rewrite docs assume that you are in a subdirectory (e.g. /xyz) and not in the top-level directory (e.g. /). If I don't add a RewriteBase directive, Apache returns the full physical path which, of course, fails.
It appears that the domain name + the trailing slash are held by the server and then recombined with the RewriteBase parameter + the rewritten URL. Since I can't specify a null RewriteBase parameter, I get an extra slash.
My .htaccess looks like this:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^about$ xyz/about.php [R,L]
Ideas?
Thanks,
Cameron
P.S. Elsewhere, someone suggested using the search term of /about ... which doesn't work since the initial slash doesn't exist by the time the regex is applied.
Welcome to WebmasterWorld!
This code has a problem, and it's not clear if you want to do an external redirect or an internal rewrite.
For an external redirect, which returns a response telling the browser to ask for the resource at a new URL, use:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^about$ [b]http://www.example.com/[/b]xyz/about.php [R[b]=301[/b],L]
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^about$ /xyz/about.php [[b]L[/b]]
If changing the code does not work, you may have a server configuration problem -- possibly related to virtual host naming syntax and/or to the UseCanonicalName setting. If you do not have access to httpd.conf, ask your host to set UseCanonicalName off to see if that fixes the problem.
Jim
Thanks for the welcome!
And thanks so much for the information. You were right on the money. My brain had processed the server vs. client redirect capability but hadn't put that together with the need to mod the rewritten URL depending upon which style I was using.
Removing the [R] flag results in the desired behavior.
Thanks again!
Cameron