如何根据开发/生产环境重写http root(htaccess问题)

发布于 2024-09-16 02:24:49 字数 685 浏览 7 评论 0原文

我有一个开发框,其中包含我的网站:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟若柳尘 2024-09-23 02:24:49

我想说的是,不要使用与生产系统不同的根路径来开发它。

在您的测试系统上创建虚拟主机并不困难 - 事实上很简单。只需使用一个即可。

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.

溇涏 2024-09-23 02:24:49

就我个人而言,我建议使用虚拟主机和主机文件,这样您在环境之间移动时就不必进行任何更改。只需决定用于您的开发的域(例如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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文