2016-04-22 61 views
2

我正在嘗試爲舊的Kayako幫助臺URL設置一些301重定向。舊的URL是;在.htaccess中匹配問號

example.com/index.php?/rest_of_url

我已經成立了這樣重寫URL的是漂亮example.com/rest_of_url,我試圖以301重定向所有的舊網址的新。我嘗試了以下方法,但他們似乎沒有工作;

RewriteRule ^index.php?/(.*)?$ /$1 [R=301,L] 

RewriteRule ^index.php\?/(.*)?$ /$1 [R=301,L] 

RewriteRule ^index.(.*)/(.*)?$ /$2 [R=301,L] 

我不太明白。

編輯:

這裏是整個.htaccess文件

<IfModule mod_rewrite.c> 
RewriteEngine On 

RewriteCond %{HTTPS} off 
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

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

RewriteCond $1 !^(admin|api|console|favicon\.ico|robots\.txt|sitemap\.xml|index\.php|tiny_mce_gzip\.php|cron|onsite|staff|rss|setup|visitor|winapp|wallboard|__swift) [NC] 
RewriteCond $1 !\.(jpg|jpeg|png|gif|js|css|htm|html)$ [NC] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L] 

RewriteCond $1 !^(favicon\.ico|robots\.txt|sitemap\.xml|index\.php|tiny_mce_gzip\.php|__swift) [NC] 
RewriteCond $1 !\.(jpg|jpeg|png|gif|js|css|htm|html)$ [NC] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([a-zA-Z0-9]*)/(.*)$ $1/index.php?/$2 [L] 
</IfModule> 

回答

2

的部分後的問號是不是在重寫規則URL。
你必須使用%{QUERY_STRING}

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

%1是在最後RewriteCond第一(.*)

在你的情況,沒有循環使用:

RewriteCond %{THE_REQUEST} \s/+index\.php\?([^\s&]+) [NC] 
RewriteRule^/%1? [R=302,L,NE] 
+0

感謝。它似乎沒有正常工作,但它似乎是重定向到'example.com/rest_of_url?/ rest_of_url'的任何想法? – Wasim

+0

是的,對不起,現在沒問題,在'%1'後面用''''''''''''' – Croises

+0

謝謝,這確實有效。唯一的問題是它做了無限的重定向循環。我不確定這是爲什麼。我已經用整個'.htaccess'更新了這篇文章,因爲它是另一個有衝突的東西。感謝幫助。 – Wasim