我试图仅覆盖以.html结尾的URL,以删除扩展名,然后在末尾添加斜杠。
这将导致类似foo.com/bar.html
到foo.com/bar/
的情况,并且仍会在目录的根目录中检索html文件。
以下代码可以正常工作,但无法再找到要加载的.html文件。
这是在WordPress上,我认为了解这一点对使其正常工作非常重要。
#test (does what it needs to but does not grab the file)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^/]+)/?$ $1.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ $1_$2.html [L]
# end test
答案 0 :(得分:0)
别担心! RewriteRule ^([^/]+)/?$ $1.php
上的简单复制和粘贴错误需要为RewriteRule ^([^/]+)/?$ $1.html
#test (does what it needs to but does not grab the file)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^/]+)/?$ $1.php # Obviously needs to be .html, not .php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ $1_$2.html [L]
# end test