【发布时间】:2018-03-24 16:42:56
【问题描述】:
想要将参数 url 重定向到 seo 友好的 url
https://example.com/a.php?slug=vr-promised-us-the-future-too-bad-we-re-stuck-in-the-present
到
https://example.com/vr-promised-us-the-future-too-bad-we-re-stuck-in-the-present
和
https://example.com/tag.php?id=Virtual-reality
到
https://example.com/tag/Virtual-reality
我当前的 .htaccess 代码
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/?$ a.php?slug=$1 [L]
RewriteCond %{HTTP_HOST} ^www\. [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R]
【问题讨论】:
-
这个 htaccess 仍然是动态的(多域),并且没有域正在以困难的方式写入。所以不要更改它并使用主机管理中的 CNAME 添加站点域并添加 vhost 以指向新的本地文件夹。
-
@headmax 感谢您的回复,实际上我的问题是如何阻止重复的网址(重定向旧 => /a.php?slug=vr-promised-us-the-future-too-bad-we -re-stuck-in-the-present to /vr-promised-us-the-future-too-bad-we-re-stuck-in-the-present)
标签: php apache .htaccess mod-rewrite seo