嗨 我想重写我的网站链接以使其更友好。网页链接是这种形式:
http://www.mysite.com/index.php?content=somepage
为了使搜索引擎优化更友好,我想将链接更改为 http://www.mysite.com/somepage.html
但声明 .htaccess 规则以便用户点击 http://www.mysite.com/somepage.html它被重定向到 http://www.mysite.com/index.php?content=somepage
你能帮我解决相关的htaccess规则吗?
最佳答案
不完全是您想要的,但可能更好。这会将 example.com/hello/等 URL 更改为 example.com/?page=hello。 (在这种情况下没有必要指定 index.php)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^([A-Za-z0-9-_/\.]+)\/$ /?page=$1 [L]
</IfModule>
如果您确实想要 .html(不确定为什么要这么做!)试试这个(未经测试):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^([A-Za-z0-9-_/\.]+).html/$ /?page=$1 [L]
</IfModule>
关于.htaccess - 重写链接,使链接地址更加 seo 友好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5444792/