2014-10-27 101 views
1

基本上我有兩個不同的規則/任務,這些規則/任務應該組合在一組規則中。.htaccess組合規則(將非ssl重定向到ssl和exections)

任務1

所有非SSL頁面都被重定向到SSL。我的解決方案已經在自己的工作。

假人例如:

非SSL://sample.some-website.ch/de/test.html - > SSL://sample.some-website.ch/de/test.html

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 
RewriteCond %{HTTP_HOST} ^sample.some-website.ch$ 
RewriteRule ^(.*)$ "https\:\/\/sample\.some\-website\.ch\/$1" [R=301,L] 

任務2

所有舊的一個.phtml鏈接都被重定向到新的SSL頁面(單獨)。我的解決方案是自己開發的(2個虛擬示例)

non-ssl://sample.some-website.ch/xyz.phtml - > ssl://sample.some-website.ch/de/newlink html的 非SSL://sample.some-website.ch/123.phtml - > SSL://sample.some-website.ch/en/something.html

redirect 301 /xyz.phtml https://sample.some-website/de/newlink.html 
redirect 301 /123.phtml https://sample.some-website.ch/en/something.html 

問題

我需要一個結合了任務1和任務2的.htaccess解決方案。 某些舊的.phtml(非ssl)鏈接必須重定向到新的特定SSL頁面AND所有'其他正常'非SSL鏈接必須自動重定向到其對應的SSL頁面。 最後只顯示ssl頁面。

任何想法? 謝謝。漢斯。

+0

你能展現完整的.htaccess? – anubhava 2014-10-27 13:55:21

+0

https://www.dropbox.com/s/kn3mtgwe2y7zahc/htaccess-code.txt?dl=0 – Strandel 2014-10-27 14:56:40

回答

1

你可以有你的.htaccess這樣的:

RewriteEngine On  
RewriteBase/

# redirect old links 
RewriteRule ^xyz\.phtml$ https://sample.some-website/de/newlink.html [L,R=301] 
RewriteRule ^123\.phtml$ https://sample.some-website.ch/en/something.html [L,R=301] 

# add https to your site 
RewriteCond %{HTTPS} off 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE] 

# route .html file to index.php  
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule .*\.html$ index.php [L] 

# earlier rules to rewrite to index.php  
RewriteRule ^[a-z]{2}(-[A-Z]{2})?/$ index.php [L] 
RewriteRule ^([a-z]{2}(-[A-Z]{2})?)$ $1/ [R=301,L] 
+0

優秀的解決方案。 要強制總是www,我添加了以下規則: RewriteCond%{HTTP_HOST}!^ sample.some-website.ch $ RewriteRule。* https://sample.some-website.ch% {REQUEST_URI} [R = 301,L] – Strandel 2014-10-28 07:58:20

+0

是的,這應該爲強制'www'工作,很高興它解決了。 – anubhava 2014-10-28 08:00:11