【问题标题】:How to remove ? from the url using htaccess如何去除?从使用 htaccess 的 url
【发布时间】:2012-09-17 21:44:58
【问题描述】:

我有一个网址http://www.domain.com/postname/?a_different_world

我需要改成http://www.domain.com/postname/a_different_world

如何去除?从 URL 使用 Htacccess(Wordpress)

我使用以下 htaccess 代码。但它不起作用

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php-$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /domain.com/index.php [L]
RewriteRule ^/postname/([0-9]+)$ /? $1 [L,QSA] 

【问题讨论】:

  • 请在您的示例域中使用example.com,而不是domain.com(它归某人所有,可能不是您)。

标签: wordpress apache .htaccess url seo


【解决方案1】:

规则匹配字符串去除查询字符串(? 之后的所有内容)。因此,您想放弃 ?并明确使用这样的查询字符串(而不是你的最后一条规则)

RewriteCond %{QUERY_STRING} ^([\w\-]+)$
RewriteRule ^postname/$ postname/%1?   [L]

请注意,您应该删除前导 / 因为这不会匹配,因为 .htaccess 规则匹配字符串会删除前导 /;还要注意 ?在 QSA 标志的替换模式和省略中,因为您不想要附加查询字符串。

还要将此规则移到上一个条件/规则之上,因为第二个规则将在您的邮件名称模式上触发,因此除非您将其上移,否则您将永远无法达到此规则。

【讨论】:

    猜你喜欢
    • 2023-03-31
    • 2015-08-28
    • 1970-01-01
    • 1970-01-01
    • 2012-09-25
    • 1970-01-01
    • 1970-01-01
    • 2012-01-04
    • 2011-05-15
    相关资源
    最近更新 更多