.htaccess
我们的目录中的内容document_root
如下:
RewriteEngine on
RewriteRule ^posts/1/first-post-title$ /posts/1.html [L]
RewriteCond %{REQUEST_URI} ^/posts/1
RewriteCond %{REQUEST_URI} !/^posts/1/first-post-title$
RewriteRule (.*) posts/1/first-post-title [R=301,L]
配置设计使得以下 URL 全部指向“http://localhost/posts/1/first-post-title“:
- “http://localhost/posts/1“
- “http://localhost/posts/1/错误标题“
- “http://localhost/posts/1/first-post-title“
第二行工作正常,“http://localhost/posts/1/first-post-title“查看/posts/1.html
不幸的是,当使用其他任何 URL 时,用户都会被重定向到“http://localhost/path/to/document_root/posts/1/first-post-title“
答案1
将您的重写更改为绝对,例如而不是这样:
RewriteRule (.*) posts/...
用这个:
RewriteRule (.*) /posts/...