我有这个网址www.sample.com/news-center/details/idparameter
和
我想将其重定向到此网址www.sample.com/news-center/details.html/idparameter
我有一个新闻中心文件夹和一个details.html
文件,下面的规则在详细信息文件夹中。如何重写它以便它将转到新闻中心文件夹中的details.html
?
的.htaccess
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^home/?$ index.html [NC,N]
RewriteRule ^news-center/?$ news-center/index.html [NC,N]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
</IfModule>
我尝试添加以下代码,但它无效。
RewriteRule ^/details/(.+)\.html$ details.html [R]
答案 0 :(得分:0)
试试这个:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^home/?$ index.html [L]
RewriteRule ^news-center/?$ /news-center/index.html [L]
RewriteRule ^news-center/details/(.+)\.html$ /news-center/details.html/$1 [R=301,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
</IfModule>
答案 1 :(得分:0)
我尝试了下面的代码并且它有效!虽然我的角度现在不起作用但是 我最初的问题现在已经解决了。
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^home/?$ index.html [NC,N]
RewriteRule ^news-center/?$ news-center/index.html [NC,N]
RewriteRule ^news-center/details/([^\.]+)$ news-center/details.html [NC,N]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
</IfModule>