How to rewrite http root depending on development / production environment (htaccess question)
I have a development box which contains my site in:
http://localhost/dev/
My production environment is just:
http://mydomain.com/
I have all my PHP scripts adjusting to different paths automatically, but everytime I upload changes to my .htaccess file, I need to manually change any mentions of my http_root directory "/dev/" to "/开发者_JAVA技巧".
How can I automatically compensate for the changing root directory? I've looked through the apache docs but can't seem to get anything to work.
A couple examples of rewrites:
#Rewrite Index Requests
RewriteRule ^index\.(php|htm|html|asp|aspx|cfm|shtml|shtm)/?$ /dev/ [R=301,NC,L]
RewriteRule ^home\.(php|htm|html|asp|aspx|cfm|shtml|shtm)/?$ /dev/ [R=301,NC,L]
#Rewrite contact page requests
RewriteRule ^(.*)contact\.php/?$ /dev/Contact-Page [R,NC,L]
RewriteRule ^Contact-Page/?$ contactpage\.php [NC,L]
Thanks in advance.
I'd say just don't dev it with a different root-path than the production system.
It's not that difficult to create a virtual host on your test system - trivial in fact. Just use one.
Personally I would recommend using vhosts and your hosts file so that you don't have to make any changes when moving between environments. Simply decide on a domain for your development such as domainname.dev, and add this to your hosts file. Then add a vhost for that domain that has the /dev/ folder as it's root.
精彩评论