Apache的多重写规则规则、Apache

由网友(对方正在输入...)分享简介:我有2套重写规则。这是虚拟主机:I have a 2 sets of rewrite rules. This is the Virtual Host:ServerName datingjapan.coServerAlias *.datingjapan.coRewriteEngin...

我有2套重写规则。这是虚拟主机:

I have a 2 sets of rewrite rules. This is the Virtual Host:

<VirtualHost *:80>
    ServerName datingjapan.co
    ServerAlias *.datingjapan.co
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www. [NC]
    RewriteRule ^(.*) http://www.%{HTTP_HOST}$1 [R=301,L]
    DocumentRoot /var/www/html/datingjapan.co
</VirtualHost>

和这是.htacess

and this is the .htacess

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

我一直在试图给的.htaccess添加到虚拟主机,所以我可以删除.htaccess文件 - 下面是一个例子,但我得到的网站显示:

I have been trying to add the .htaccess to the Virtual Host so I can remove the .htaccess file - below is an example, but I get the site to show:

<VirtualHost *:80>
    ServerName datingjapan.co
    ServerAlias *.datingjapan.co
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.*)$ index.php?/$1
    RewriteCond %{HTTP_HOST} !^www. [NC]
    RewriteRule ^(.*) http://www.%{HTTP_HOST}$1 [R=301,L]
    DocumentRoot /var/www/html/datingjapan.co
</VirtualHost>

据我所知,[L]表示最后一个规则相匹配,所以我已删除了这一点,但它仍然无法正常工作。

I understand the [L] means last rule to match so I have removed that but it still doesn't work.

我在想什么吗?我试图扭转了规则。

What am I missing here? I've tried reversing the rules.

三江源

推荐答案

将仍然需要为最后一个标志是标示每一个重写规则的结束。排序规则也是重要的。改变你的code到这一点:

L will still be needed as Last flag is for marking end of each rewrite rule. Ordering of rules is also important. Change your code to this:

<VirtualHost *:80>
    ServerName datingjapan.co
    ServerAlias *.datingjapan.co
    DocumentRoot /var/www/html/datingjapan.co

    RewriteEngine on

    RewriteCond %{HTTP_HOST} !^www. [NC]
    RewriteRule ^(.*) http://www.%{HTTP_HOST}$1 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.*)$ /index.php?/$1 [L,QSA]
</VirtualHost>
阅读全文

相关推荐

最新文章