我们在document_root目录下的.htaccess如下所示:
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]
该configuration的devise使得以下URL将全部指向“ http:// localhost / posts / 1 / first-post-title ”:
第二行工作正常,“ http:// localhost / posts / 1 / first-post-title ”在/posts/1.html
不幸的是,当使用其他的URL时,用户被redirect到“ http:// localhost / path / to / document_root / posts / 1 / first-post-title ”
改变你的重写是绝对的 ,比如:
RewriteRule (.*) posts/...
用这个:
RewriteRule (.*) /posts/...