.htaccess - 重写链接,使链接地址更加 seo 友好

标签 .htaccess seo

嗨 我想重写我的网站链接以使其更友好。网页链接是这种形式:

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/

相关文章:

php - 直接从 codeigniter 的 application\view 文件夹访问特定文件夹/文件

php - 如何修改 .htaccess 文件以提供 QUERY_STRING?

.htaccess - htaccess 无扩展名重写

javascript - 如何将 widget webapp 框架与 SEO 友好的 CSS 和 JS 文件结合起来

php - PHP 中的 SEO 友好 URL

html - 如何 htaccess 301 重定向在 url 中带有问号的页面

php - .htaccess URL 重写导致 CSS 问题

.htaccess - 通过 301 重定向 .htaccess 的 404 错误以进行 SEO 等

seo - 将opencart 1.5.6迁移到3.0.2.0会影响seo吗?

seo - 在谷歌搜索中显示所有页面