我的htaccess陷入了无限循环。我正在尝试从网址中剥离.html
扩展名(如果有的话),然后将剩余的字符串用作查询字符串。
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=302,L]
RewriteRule ^resources/blog$ /resources/blog/ [R=302,L,QSA]
RewriteRule ^resources/blog/$ resources/blog.php [L,QSA]
RewriteRule ^resources/blog/.*?([^\.\/]*)$ resources/blog.php?pname=$1 [L,QSA]
更新:
这是现在的样子。故障排除时,我已经评论了一些东西。
Options +SymLinksIfOwnerMatch -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Redirect to URL without .html extension (Pretty URL)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=302]
# Pretty url for Couch CMS blog
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^resources/blog/.*?([^\.\/]*)$ resources/blog.php?pname=$1 [L,QSA,END]
RewriteRule ^resources/blog$ /resources/blog/ [R=302,L,QSA]
RewriteRule ^resources/blog/$ resources/blog.php [L,QSA]
# RewriteRule ^resources/blog/([1-2]\d{3})/(?:(0[1-9]|1[0-2])/(?:(0[1-9]|1[0-9]|2[0-9]|3[0-1])/)?)?$ resources/blog.php?d=$1$2$3 [L,QSA]
# RewriteRule ^resources/blog/[^\.]*?([^/\.]*)/$ resources/blog.php?fname=$1 [L,QSA]
# RewriteRule ^resources/blog/[^\.]*?([^/\.]*)$ "$0/" [R=302,L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]
</IfModule>
更新2
文件结构如下:
/
|-- static_html_files/
|-- resources/
|----- blog.php
|----- newsletter.html
|-- .htaccess
|-- index.html
大多数文件是静态文件,需要通过从文件中删除.html扩展名“修饰”它们的URL,然后使用漂亮的URL重定向到该文件。
Blog.php也必须美化,并且Couch CMS生成的链接也需要重写。重写沙发cms链接的规则是不断循环的规则。
更新3
似乎某处有301重定向,但是我的htaccess中没有301重定向?不知道从这里去哪里或在哪里寻找此重定向。请参阅下面的“重定向检查”结果:
https://xxxxx.ca/resources/blog/yyyyy
HTTP/1.1 301 Moved Permanently
Date: Tue, 25 Jun 2019 20:58:31 GMT
Server: Apache
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Set-Cookie: PHPSESSID=poplcjkqcgd4gk57c1l3lcdjg7; path=/
Location: https://xxxxx.ca/resources/blog/yyyyy.html
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
https://xxxxx.ca/resources/blog/yyyyy.html
HTTP/1.1 302 Found
Date: Tue, 25 Jun 2019 20:58:31 GMT
Server: Apache
Location: https://xxxxx.ca/resources/blog/yyyyy
Content-Length: 263
Content-Type: text/html; charset=iso-8859-1
[RINSE & REPEAT AD NAUSEAM]
更新4
经过一些调试后,我似乎遇到了mod_rewrite和'add path info postfix'的Apache问题,通常可以通过指定-MultiViews和/或在规则中添加DPI标志来解决,但这些似乎都不能解决任何问题我的问题。