Forum Moderators: phranque

Message Too Old, No Replies

RewriteBase

         

nickCR

8:53 pm on Dec 29, 2011 (gmt 0)

10+ Year Member



First question: Is RewriteBase even necessary if the .htaccess is in a sub directory? For example www.mydomain.com/dev/?

Second question: Is there any way to redirect to the RewriteBase and if I don't need the RewriteBase how could I make it redirect to the root where the current .htaccess is?

This is to say I have:

RewriteRule ^code/$ / [R=301,L]


I would want something like this

RewriteRule ^code/$ RewriteBase [R=301,L]


This is due to the need to change multiple items in the .htaccess when I'm deploying from dev to the live.

Third question: Without the RewriteBase would relative rules still work?

RewriteRule ^code/(.*)$ code/new/$1 [R=301,L]


Thanks in advance!

lucy24

12:32 am on Dec 30, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think it's better for you to think in terms of what you want to have happen-- in English-- rather than get prematurely tangled up in RewriteBase. That is, first you figure out what you want to do. Then figure out how to do it.

But since you are redirecting anyway, why not lay out the full protocol-plus-domain? Then you can accomplish your with/without www redirect at the same time.

The exact details of what will or will not work depend partly on your server configuration, which sounds as if it's out of your control. At a minimum, put / at the front of every redirect.

g1smd

1:16 am on Dec 30, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



When mod_rewrite is used to generate redirects, it is dealing with URLs as used "out there" on the web and not with filepaths as used "here" inside the server. The redirect target should include protocol and domain name information. The rule responds to a request for a particular URL by issuing a 301 header which contains details of a different URL that the browser or bot should request in a new HTTP transaction. As such, the rule target should specify either a complete literal URL or else specify a URL that is built with literal parts combined with data optionally imported from one or more backreferences.

Is your dev site in a folder of the main site? If so, consider the simpler option that comes with moving your dev-site to a separate folder and referencing it from the web as a sub-domain. That way, the folder-levels can be identical on the live and the dev site, and only minimum "dev => www" editing is required for deployment.

nickCR

5:02 am on Dec 30, 2011 (gmt 0)

10+ Year Member



Thanks for your responses.

g1smd has me convinced. I'll be moving my development environment in the sub-domain direction. And right on the money with having it at top level, which was actually one of the only things that I haven't been able to sort out yet. With such a very small change when deploying it really is the best route to take.

This will also fix some issues I'm having with the rules. I'll stick to the full path rewrites as I get what you mean, it just see's just the url. So why make it work to figure out where you want it to go, just tell it outright :)