如何根据开发/生产环境重写http root(htaccess问题)
我有一个开发框,其中包含我的网站:
http://localhost/dev/
我的生产环境只是:
http://mydomain.com/
我将所有 PHP 脚本自动调整到不同的路径,但每次我将更改上传到 .htaccess 文件时,我都需要手动更改任何提及的 http_root目录“/dev/”到“/”。
如何自动补偿根目录的变化? 我已经查看了 apache 文档,但似乎没有任何效果。
几个重写的例子:
#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]
提前致谢。
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 "/".
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想说的是,不要使用与生产系统不同的根路径来开发它。
在您的测试系统上创建虚拟主机并不困难 - 事实上很简单。只需使用一个即可。
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.
就我个人而言,我建议使用虚拟主机和主机文件,这样您在环境之间移动时就不必进行任何更改。只需决定用于您的开发的域(例如domainname.dev),并将其添加到您的主机文件中。然后为该域添加一个虚拟主机,该域的根目录为 /dev/ 文件夹。
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.