Forum Moderators: phranque
RewriteRule ^blah/$ /yada/ [R]
The address bar should still show /blah/, right?
For some reason it's not doing this for me. Any clues on why?
> ...Any clues on why?
Yes, because by using the [R] (redirect) flag, you have explicitly told mod_rewrite to do an external 302 redirect (which involves the client browser), so the browser will always update it's address bar before re-requesting the content from the new URL.
I believe you'll be happier with an purely-internal rewrite:
RewriteRule ^blah/$ /yada/ [b][L][/b]
Jim
One more question. If I have a non-absolute link on the page, say to "images/picture.png" in the yada folder. The rewriterule makes the page look for the image in the blah folder. Is there any way to process the local URI's on the page to use the actual location of the page?
One more question. If I have a non-absolute link on the page, say to "images/picture.png" in the yada folder. The rewriterule makes the page look for the image in the blah folder. Is there any way to process the local URI's on the page to use the actual location of the page?
In order to avoid confusion and make thinking about these issues easier in the future, remember that it is the client browser that resolves relative URL-paths, not the server. So, the browser will resolve the on-page relative image URL-path relative to the current page's "directory level" and then issue a request for the image at that directory level. If that request then matches a rewriterule on the server, it will be rewritten.
So, in this case, you will find that you need to rewrite images *back* to the original directory, and avoid rewriting them on the front-end too.
# Rewrite non-image requests from /blah to /yada
RewriteCond %{REQUEST_URI} !\.(gif¦jpe?g¦png)$
RewriteRule ^blah/(.*)$ /yada/$1 [L]
#
# Rewrite browser-resolved relative image links back to original directory
RewriteRule ^yada/([^.]+\.(gif¦jpe?g¦png))$ /blah/$1 [L]
If you keep all of your images in a specific subdirectory, you can simplify the rules a bit, too:
# Rewrite non-image requests from /blah to /yada
RewriteCond %{REQUEST_URI} !/images
RewriteRule ^blah/(.*)$ /yada/$1 [L]
#
# Rewrite browser-resolved relative image links back to original top-level image directory
RewriteRule /images/(.*)$ /images/$1 [L]
Jim