3

我正在帮助一个朋友建立一个网站,我创建了几个 php 页面,然后他将这些页面复制到了根目录。问题是 htaccess 文件的设置方式使我无法访问我创建的任何新 php 文件,但我可以访问所有 html 文件。我查看了很多用于编辑 htaccess 的文档,但我无法使其工作。任何帮助表示赞赏。我添加的新页面是contact.php、show-captcha.php 和thank-you.php

RewriteEngine on
RewriteRule ^(.*)\.htm$ $1.php [NC]

#RewriteCond %{REMOTE_ADDR} !71\.239\.5\.36
#RewriteCond %{REQUEST_URI} !/maintenance.html$
#RewriteCond %{REQUEST_URI} !/img(.*)$
#RewriteCond %{REQUEST_URI} !/sync/$
#RewriteRule $ /maintenance.html [R=302,L]

##Errors##
ErrorDocument 400 /error.php
ErrorDocument 401 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php

##Redirect##
RewriteCond %{HTTP_HOST} ^www.example.net [NC]
RewriteRule ^(.*)$ http://example.net/$1 [L,R=301]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ https://example.net/$1 [R,L]

##Common Files##
RewriteRule ^(.*)\~\57(.*)$ $1Main.php?file=$2 [NC]
RewriteRule ^(.*)ajax\57(.*)$ $1Main.php?ajax&$2 [NC]
RewriteRule ^(.*)sync\57(.*)$ $1Main.php?sync&$2 [NC]
RewriteRule ^(.*)backup\57(.*)$ $1Main.php?backup&$2 [NC]
RewriteRule ^(.*)SampleDoc(\57)(.*[^\57])(\57?)$ $1index.php?count=$3 [NC]

##REDIRECTS##
RewriteRule ^(.*)menu(\57)(.*[^\57])(\57)(.*[^\57])$ $1menu.php [NC]
RewriteRule ^(.*)menu(\57)(.*[^\57])(\57?)$ $1menu.php [NC]
RewriteRule ^(.*)menu(\57?)$ $1menu.php [NC]

RewriteRule ^(.*)checkout(\57)(.*[^\57])(\57)(.*[^\57])$ $1checkout.php [NC]
RewriteRule ^(.*)checkout(\57)(.*[^\57])(\57?)$ $1checkout.php [NC]
RewriteRule ^(.*)checkout(\57?)$ $1checkout.php [NC]

RewriteRule ^(.*)ThankYou(\57)(.*[^\57])(\57?)$ $1ThankYou.php?$3 [NC]
RewriteRule ^(.*)ThankYou(\57?)$ $1ThankYou.php [NC]

RewriteRule ^(.*)Contact(\57)(.*[^\57])(\57?)$ $1contact.php?$3 [NC]
RewriteRule ^(.*)Contact(\57?)$ $1contact.php [NC]

RewriteRule ^(.*)account(\57)(.*[^\57])(\57)(.*[^\57])(\57)(.*[^\57])$ $1account.php?type=$3&email=$5&code=$7 [NC]
RewriteRule ^(.*)account(\57)(.*[^\57])(\57?)$ $1account.php?type=$3 [NC]
RewriteRule ^(.*)account(\57?)$ $1account.php [NC]

RewriteRule ^(.*)catering(\57)(.*[^\57])(\57)(.*[^\57])$ $1catering.php?$3$5 [NC]
RewriteRule ^(.*)catering(\57)(.*[^\57])(\57?)$ $1catering.php?$3 [NC]
RewriteRule ^(.*)catering(\57?)$ $1catering.php [NC]

RewriteRule ^(.*)changepassword\57(.*[^\57])\57(.*[^\57])$ $1account.php?type=changepssd&email=$2&code=$3 [NC]
RewriteRule ^(.*)join(\57)(.*[^\57])(\57)(.*[^\57])$ $1account.php?type=join&email=$5&code=$7 [NC]

我尝试添加contact.php,但您可以看到它没有帮助。

4

2 回答 2

1

如果您不打算将路径变量移动到查询字符串,则根本不需要重写规则。只需删除联系页面的 RewriteRules。如果您仍然收到未找到的页面,请删除

ErrorDocument 500 /error.php

所有错误,从页面未找到到服务器错误都得到相同的 error.php。您的contact.php 中可能有一些错误,这就是您总是得到这个页面的原因。

希望有帮助!

于 2012-09-20T21:57:01.553 回答
-1

尝试删除与联系人的现有线路

#RewriteRule ^(.*)Contact(\57)(.*[^\57])(\57?)$ $1contact.php?$3 [NC]
#RewriteRule ^(.*)Contact(\57?)$ $1contact.php [NC]

并添加这些:

RewriteRule ^(.*)contact(\57)(.*[^\57])(\57)(.*[^\57])$ $1contact.php [NC]
RewriteRule ^(.*)contact(\57)(.*[^\57])(\57?)$ $1contact.php [NC]
RewriteRule ^(.*)contact(\57?)$ $1contact.php [NC]

并注意区分大小写。

于 2012-09-18T00:46:12.403 回答