1

我需要对我的网站进行更改,但在我确定它们是正确的之前,我不想将它们添加到我的真实帐户中。我的帐户是在 GoDaddy 上的,据他们说,我能做到这一点的唯一方法是将我的所有文件移动到另一个文件夹并通过转到该文件夹​​来测试我的更改。我没有从 Web 浏览器调用 Duphil.com,而是使用 Duphil.com/DuphilWork。.htaccess 文件中的编码不会让我留在这个文件夹中。

这是编码:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

ErrorDocument 404 /index.php?page=404
ErrorDocument 403 /index.php?page=403

RewriteRule ^$ /index.php
RewriteRule ^about/$ /index.php?page=about
RewriteRule ^oilfield/$ /index.php?page=oilfield
RewriteRule ^pipeline/$ /index.php?page=pipeline
RewriteRule ^safety/$ /index.php?page=safety
RewriteRule ^sales/$ /index.php?page=sales
RewriteRule ^contact/$ /index.php?page=contact
RewriteRule ^stateLicensures/$ /index.php?page=stateLicensures
RewriteRule ^keyPersonnel/$ /index.php?page=keyPersonnel
RewriteRule ^projectListings/$ /index.php?page=projectListings
RewriteRule ^legal/$ /index.php?page=legal
RewriteRule ^techDivision/$ /index.php?page=techDivision

RewriteRule ^equipment/$ /index.php?page=equipment
RewriteRule ^projectImages/$ /index.php?page=projectImages
RewriteRule ^contact/(.*)/$ /index.php?page=contact&contactName=$1

我怎样才能做到这一点?

4

1 回答 1

0

你做你的.htaccess方式很混乱。每个页面的规则都有许多缺点,其中最重要的是,如果您添加一个页面,则必须更新您的.htaccess. 另一个缺点是您不能简单地添加例外,因为您必须为每个规则添加。但是,我们可以做的一件事是将页面重写为自身,并告诉它一旦这样做就不应继续重写:

RewriteRule ^DuphilWork/(.*)$ DuphilWork/$1

RewriteRule ^$ /index.php
[..]

现在,这意味着您仍然必须在测试站点上编写您的 url 而无需重写。换句话说,它们必须是这样的:Duphil.com/DuphilWork/index.php?page=oilfield.

如果您还想在测试站点中编写更高级的 url,则当前设置的唯一方法是复制您的所有规则.htaccess并添加DuphilWork到匹配模式和其中一个副本中的重定向路径。

真正的解决方案当然是有一个这样的规则:

RewriteCondition !-f
RewriteRule ^(.*)$ /index.php?page=$1

然后确保 index.php 正确解析该页面字符串(现在包括确保页面存在。在这种情况下,解决您当前的问题变得微不足道。但是,我相信您应该能够使用我上面给出的解决方案。


使用我上面描述的涉及复制所有内容的策略,你最终会得到这样的结果:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

ErrorDocument 404 /index.php?page=404
ErrorDocument 403 /index.php?page=403

RewriteRule ^DuphilWork/$ /DuphilWork/index.php
RewriteRule ^DuphilWork/about/$ /DuphilWork/index.php?page=about
RewriteRule ^DuphilWork/oilfield/$ /DuphilWork/index.php?page=oilfield
RewriteRule ^DuphilWork/pipeline/$ /DuphilWork/index.php?page=pipeline
RewriteRule ^DuphilWork/safety/$ /DuphilWork/index.php?page=safety
RewriteRule ^DuphilWork/sales/$ /DuphilWork/index.php?page=sales
RewriteRule ^DuphilWork/contact/$ /DuphilWork/index.php?page=contact
RewriteRule ^DuphilWork/stateLicensures/$ /DuphilWork/index.php?page=stateLicensures
RewriteRule ^DuphilWork/keyPersonnel/$ /DuphilWork/index.php?page=keyPersonnel
RewriteRule ^DuphilWork/projectListings/$ /DuphilWork/index.php?page=projectListings
RewriteRule ^DuphilWork/legal/$ /DuphilWork/index.php?page=legal
RewriteRule ^DuphilWork/techDivision/$ /DuphilWork/index.php?page=techDivision

RewriteRule ^DuphilWork/equipment/$ /DuphilWork/index.php?page=equipment
RewriteRule ^DuphilWork/projectImages/$ /DuphilWork/index.php?page=projectImages
RewriteRule ^DuphilWork/contact/(.*)/$ /DuphilWork/ index.php?page=contact&contactName=$1

RewriteRule ^$ /index.php
RewriteRule ^about/$ /index.php?page=about
RewriteRule ^oilfield/$ /index.php?page=oilfield
RewriteRule ^pipeline/$ /index.php?page=pipeline
RewriteRule ^safety/$ /index.php?page=safety
RewriteRule ^sales/$ /index.php?page=sales
RewriteRule ^contact/$ /index.php?page=contact
RewriteRule ^stateLicensures/$ /index.php?page=stateLicensures
RewriteRule ^keyPersonnel/$ /index.php?page=keyPersonnel
RewriteRule ^projectListings/$ /index.php?page=projectListings
RewriteRule ^legal/$ /index.php?page=legal
RewriteRule ^techDivision/$ /index.php?page=techDivision

RewriteRule ^equipment/$ /index.php?page=equipment
RewriteRule ^projectImages/$ /index.php?page=projectImages
RewriteRule ^contact/(.*)/$ /index.php?page=contact&contactName=$1
于 2012-11-08T21:40:45.377 回答