2015-02-10 166 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