【问题标题】:Redirect / remove links by question mark通过问号重定向/删除链接
【发布时间】:2019-04-22 16:20:01
【问题描述】:

我需要删除所有带有问号的链接。这些是未被 Google 索引的链接。

我找不到这个问题的解决方案。

例子:

http://example-page.pl/pl?start=18 --> http://example-page.pl/pl

HTACCESS:

...

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

...

【问题讨论】:

标签: .htaccess redirect


【解决方案1】:

使用 RewriteCond 检查是否有查询字符串,然后使用 RewriteRule 仅重定向 url 的第一部分。


输入:http://example-page.pl/pl?start=18

RewriteCond %{QUERY_STRING} .
RewriteRule ^(.*)$ /$1? [R,L]

输出:http://example-page.pl/pl


您可以通过htaccess.madewithlove.be查看此工作。

【讨论】:

  • 非常感谢!该解决方案完美运行:)
猜你喜欢
  • 2012-06-13
  • 2023-03-23
  • 2016-06-28
  • 1970-01-01
  • 2012-04-14
  • 1970-01-01
  • 2015-05-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多