我有个网址重写的问题。我网站的所有主题网址都指向www.mywebsite.com/topic.php? topic =id,我想将这些urls更改为www.mywebsite.com/Top-id.html。
我是在一个.htaccess文件中这样做的:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^topic-([0-9]+)\.html$ /topic.php?topic=$1现在,我希望所有指向/topic.php?topic=id的url都像Top-id.html一样被重写,以便只为用户显示一个url而不重写我的所有代码。可以这样做吗?
我用这种方式尝试了R标志:
RewriteRule ^topic-([0-9]+)\.html$ /topic.php?topic=$1 [R]但是它所做的与我想要的完全相反,因为它将所有的urls转换为( topic.php?topic=id ),比如(Top-id.html)。
我指定,我不是在寻找的解决方案--“复制内容问题”
任何帮助都是很好的,谢谢
发布于 2016-06-24 12:44:18
你可以试试这个,我为你跳这个作品
RewriteCond %{THE_REQUEST} \s/topic\.php\?id=([_0-9a-zA-Z-]+)\s [NC]
RewriteRule ^%1? [R=301,L]
RewriteRule ^([_0-9a-zA-Z-]+)$ /topic.php?id=$1 [L]
RewriteCond %{THE_REQUEST} \s/topic\.php\?id=([_0-9a-zA-Z-]+)\s [NC]
RewriteRule ^ %1.html? [R=301,L]
RewriteRule ^([_0-9a-zA-Z-]+?)(?:\.html)?$ /index.php?id=$1 [NC,L]发布于 2016-06-24 12:46:44
将以下内容置于现有规则之上( RewriteEngine on行后):
RewriteCond %{THE_REQUEST} /topic\.php\?id=(.+)\sHTTP [NC]
RewriteRule ^ /topic-%1.html [L,R]发布于 2016-06-24 12:58:55
您只需要使用以下内容:
RewriteEngine On
RewriteRule ^topic-([^-]*)\.html$ /topic.php?topic=$1 [L]https://stackoverflow.com/questions/38013685
复制相似问题