正如 Marc B 所建议的那样,检查日志是最好的起点。您应该启用更详细的 mod_rewrite 日志记录,如下所示:
RewriteLog "/usr/local/var/apache/logs/rewrite.log"
RewriteLogLevel 3
不要采用RewriteLogLevel
高于 3 的详细程度。
因此,阅读您的规则,我想我可能知道您的意思。你应该试试这个:
RewriteCond %{REQUEST_URI} !form\.php$
我认为 Apache 并不关心 URL 上可能出现的查询字符串。%{QUERY_STRING}
除了 . 之外,您还可以使用一个变量%{REQUEST_URI}
。除非您有一些奇怪的 URL,其中可能包含“php”,否则我认为它们都将以“.php”结尾。
由于“sitemap.xml”看起来不错,因此您很可能应该按照它的示例并使用“\”以相同的方式转义句点字符(“.”)。
一天后,我有时间思考这些规则。
# Use simpler rules, not all that jazz you prepend, appended.
#
RewriteCond %{REQUEST_URI} form\.php$ [OR]
RewriteCond %{REQUEST_URI} sitemap\.xml$
# If %{REQUEST_URI} matches either of the previous rule,
# we skip a certain number of RewriteRules that follow.
# If you add more rules, and need to skip more, you *need* to adjust this number.
RewriteRule . - [S=2]
# Your original line reads:
#
# RewriteCond %{THE_REQUEST} ^[A-Z]+\s([^/]+)\.php\s
#
# Using "%{THE_REQUEST}" variable means you are processing
# a string like this
#
# "GET /something.html HTTP/1.1"
#
# Did you really need the HTTP method and the protocol version?
# Do something simpler. Match the the "http://host/foo/bar/baz/" portion
# Then match the first part of the PHP file name. So, if URL ends in "something.php"
# The second parenthesis will match "something". Then append ".html"
RewriteRule (^.*\/)([^/]+)(\.php)$ $1$2.html [R=301,L]
# **Then** you are trying to rewrite your HTML files to PHP? Why?
# In any case, do something similar as the last RewriteRule.
RewriteRule (^.*\/)([^/]+)(\.html)$ $1$2.php [R=301,L]
# I do not understand RewriteCond %{ENV:REDIRECT_STATUS} 200 at all
# I don't see you using this environmental variable later on in this
# snippet. Recommend the use of "PT" in case you have other stuff running
# that you want to send the rewrite target to be passed back to the
# URL mapping engine.
RewriteRule ^.*$ - [PT, QSA]
# You neglected to add the leading slash in this pattern
RewriteRule ^/index.php$ http://%{http_host} [R=301,L]