2017-02-24 37 views
2

解決我issue避免重定向的URL現在我試圖解決重定向一個長期的,更復雜的URL的問題的特定部分爲https重定向長的URL爲https

這是後行在我的.htaccess文件給我的問題:

RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L] 

index.php從不暴露在URL本身。比如這個網址應該重定向到https:

http://bootstrapcovers.com/themes/bootstrap-themes/toolsmith-1110/volvox-responsive-html5-bootstrap-template

輸入網址後,它重定向到:

[https://bootstrapcovers.com/index.php?uri=themes/bootstrap-themes/toolsmith-1110/volvox-responsive-html5-bootstrap-template][2] 

注意的index.php URI =加入我所期望的,但該頁面將重定向回主頁。如果我刪除該部分(index.php?uri =),則該網址正常工作!

如何重定向URL而不添加index.php?uri =

這裏是我完整的.htaccess文件:

# 1 Month for most static assets 
<filesMatch ".(css|jpg|jpeg|png|gif|js|ico|woff)$"> 
Header set Cache-Control "max-age=2592000, public" 
</filesMatch> 
<IfModule mod_headers.c> 
    <FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css|css)$"> 
    Header set Access-Control-Allow-Origin "*" 
    </FilesMatch> 
</IfModule> 

Options -MultiViews 
RewriteEngine on 
RewriteRule ^(.+?)/$ /$1 [R=302,NE,L] 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L] 

RewriteCond %{HTTPS} off 
RewriteCond %{THE_REQUEST} !\s/+preview [NC] 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301] 

RewriteCond %{HTTPS} on 
RewriteCond %{THE_REQUEST} \s/+preview [NC] 
RewriteRule^http://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301] 

解決任何幫助,將不勝感激。

感謝, - 保羅

回答

1

你需要做的的規則重構的一個排序和位。有這樣的方式:

# 1 Month for most static assets 
<filesMatch ".(css|jpg|jpeg|png|gif|js|ico|woff)$"> 
Header set Cache-Control "max-age=2592000, public" 
</filesMatch> 
<IfModule mod_headers.c> 
    <FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css|css)$"> 
    Header set Access-Control-Allow-Origin "*" 
    </FilesMatch> 
</IfModule> 

Options -MultiViews 
RewriteEngine on 
RewriteBase/

RewriteCond %{HTTPS} off 
RewriteCond %{THE_REQUEST} !\s/+preview [NC] 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301] 

RewriteCond %{HTTPS} on 
RewriteCond %{THE_REQUEST} \s/+preview [NC] 
RewriteRule^http://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+?)/$ /$1 [R=301,NE,L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L] 

請確保在測試此更改之前清空您的瀏覽器緩存。

+0

anubhava,我沒有在我的網址uri論據......這是必要的嗎?感謝您的反饋 – Paul

+0

但我沒有在我的答案中的任何地方提及'url參數'。我的回答是,如果您爲此要求寫了如下內容:「如何在不添加index.php的情況下重定向URL?uri =?'您是否在清除瀏覽器緩存後測試了我所建議的更改。 – anubhava

+0

我測試了你的改變,一切都很好。當我刪除.htaccess文件中的最後一項時,它會失敗。我的URL都沒有使用這種格式(index.php?uri =),所以我想我不明白爲什麼它失敗... – Paul