1、2级目录如何添加不同的rewrite规则?
How to add different rewrite rules to the 1 and 2 directory levels?
如何将 尾部斜杠 强制到 1 目录级别:
http://example.com/dir1 -> http://example.com/dir1/
和
强制 .html 后缀到 2 目录级别
http://example.com/dir1/dir2 or http://example.com/dir1/dir2/ ->
-> http://example.com/dir1/dir2.html
我尝试了这些规则,但它们似乎无法正常工作:
RewriteCond %{HTTP_HOST}/([a-zA-Z0-9_-]+)$
RewriteRule %{HTTP_HOST}/([a-zA-Z0-9_-]+)/$ [L]
RewriteCond %{HTTP_HOST}/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$
RewriteRule {HTTP_HOST}/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).html$ [L]
谢谢!
试试这些:
RewriteEngine On
RewriteBase /
# Rule number 1
RewriteRule ^([^/]+?)(\.html?)?/?$ // [L]
# Rule number 2
RewriteRule ^([^/]+/[^/]+)/?$ /.html [L]
如果您希望重写的 URL 出现在浏览器中,请将标志更改为 [R,L]
如何将 尾部斜杠 强制到 1 目录级别:
http://example.com/dir1 -> http://example.com/dir1/
和 强制 .html 后缀到 2 目录级别
http://example.com/dir1/dir2 or http://example.com/dir1/dir2/ ->
-> http://example.com/dir1/dir2.html
我尝试了这些规则,但它们似乎无法正常工作:
RewriteCond %{HTTP_HOST}/([a-zA-Z0-9_-]+)$
RewriteRule %{HTTP_HOST}/([a-zA-Z0-9_-]+)/$ [L]
RewriteCond %{HTTP_HOST}/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$
RewriteRule {HTTP_HOST}/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).html$ [L]
谢谢!
试试这些:
RewriteEngine On
RewriteBase /
# Rule number 1
RewriteRule ^([^/]+?)(\.html?)?/?$ // [L]
# Rule number 2
RewriteRule ^([^/]+/[^/]+)/?$ /.html [L]
如果您希望重写的 URL 出现在浏览器中,请将标志更改为 [R,L]