【发布时间】:2017-07-05 17:13:42
【问题描述】:
我有几个带有问号的 URL 需要删除。例如,我需要重定向这个 URL:
http://example.net/?/services
到这个网址:
http://example.net/services
我还有很多这样的东西,所以我想要一些可以用问号捕获所有内容并正确重定向它的东西。我发现的许多答案都试图使用QUERY_STRING 作为重写的条件,但是如果没有参数,这无济于事。经过一番挖掘,我找到了一个有效的RewiteCond,但RewriteRule 重定向到主页,而不是没有问号的URL。我目前拥有的是这样的:
# Remove question mark from string
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(index\.php)?\?([^&\ ]+)
RewriteRule ^ /%1? [L,R=301]
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
第一个块是我目前进行的重写,接下来的两个块用于 CMS url 路由。似乎正在发生的事情是我在第一个块中的重写没有保留 URL 的其余部分。我尝试了几种组合,但似乎无法弄清楚如何保持 URL 的其余部分完好无损。
【问题讨论】:
标签: .htaccess redirect mod-rewrite