Apache的多重写规则 [英] Apache Multiple Rewrite Rules

查看:309
本文介绍了Apache的多重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有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>

这篇关于Apache的多重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆