2015-02-10 167 views
0

我從來沒有做過重寫規則,我嘗試在google找到的所有內容都不起作用。特別是創建多個重寫規則對我來說很難,因爲我不知道正確的語法是如何以及正確的實現如何(1重寫條件或多個類似的問題)。htaccess簡單重寫規則不起作用

因此,我會很樂意得到一個結果我嘗試如下:

https://www.domain.com/our_accounts.php - >https://www.domain.com/accounts

在HTTP - > HTTPS規則已經工作。也許還有我的重寫規則的問題,因爲我可能需要在我的https規則之前添加它們?我希望你們能幫助我。

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteCond %{HTTPS} off 
    # First rewrite to HTTPS: 
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
    # Now, rewrite any request to the wrong domain to use www. 
    RewriteCond %{HTTP_HOST} !^www\. 
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
    # Rules for readable URLs 
    RewriteCond %{THE_REQUEST} ^.*/index\.php 
    RewriteRule ^(.*)index.php$ /$1 [R=301,L] 
    RewriteRule ^accounts$ /our_accounts.php [L] 
</IfModule> 

回答

1

以這種方式試試你的htacess文件。我還將HTTP和www壓縮爲一個重寫規則。只需將yoursite.com替換爲您的真實網站。

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    # First rewrite to HTTPS and redirect www: 
    RewriteCond %{HTTPS} !^on [OR] 
    RewriteCond %{HTTP_HOST} !^www\. 
    RewriteRule ^(.*)$ https://www.yoursite.com/$1 [L,R=301] 

    RewriteRule ^our_accounts.php$ /accounts [R=301,L] 

    # Rules for readable URLs 
    RewriteCond %{THE_REQUEST} ^.*/index\.php 
    RewriteRule ^(.*)index.php$ /$1 [R=301,L] 
</IfModule> 
+0

到目前爲止工作正常,但文件「our_accounts.php」到虛擬文件夾「accounts」的重寫規則仍然不起作用。我基本上都嘗試過,因爲任何設置或其他原因,這對我來說可能不起作用。順便從http-> https重寫作品,index.php到根直接工作也很好。 – kentor 2015-02-10 00:38:31

+1

'不起作用'沒有幫助。它不在做什麼,或者你得到什麼錯誤?基本上是什麼結果。這對我行得通。清除瀏覽器緩存並嘗試。 – 2015-02-10 00:41:34

+0

另外你在瀏覽器中實際嘗試的URL是什麼? – 2015-02-10 00:42:35