【问题标题】:Rewrite URL through .htaccess通过 .htaccess 重写 URL
【发布时间】:2021-03-30 14:19:35
【问题描述】:

我的网站生成的页面 URL 带有前缀 ?Script=,这对 SEO 不友好。

我想去掉这个前缀,只保留页面标题。

例如,我想转换以下网址:

example.com/?Script=aboutexample.com/about

about 是我网站的“关于”页面。

我想为所有页面设置一个忽略?Script= 的规则。

我已经通过使用以下重写规则为我的博客文章做到了这一点。

RewriteRule ^news/([0-9a-zA-Z_-]+) ?Script=news_view&uid=$1

【问题讨论】:

  • 欢迎来到 SO,所以你的意思是你在浏览器中点击 url example.com/?Script=about 并且你想重定向(在浏览器中更改 URL)到 example.com/about?请确认一次。
  • 感谢您的关注。我网站的核心文件在其 URL 上附加了 &Script=。我想将此网址 example.com/?Script=about 重写为 example.com/about 这个网址,以便当我点击 example.com/about 它没有显示 404 错误。

标签: .htaccess mod-rewrite


【解决方案1】:

这应该适合你。

RewriteEngine on

RewriteRule ^(about)/?$ /?script?=$1 [L]

如果您有更多页面,您可以将这些页面添加到模式中

RewriteEngine on

RewriteRule ^(about|page2|page3)/?$ /?script?=$1 [L]

【讨论】:

    猜你喜欢
    • 2019-02-23
    • 2015-05-29
    • 1970-01-01
    • 2021-10-21
    • 1970-01-01
    • 1970-01-01
    • 2013-05-15
    • 2011-12-17
    相关资源
    最近更新 更多