URL重写 [英] Apache Mod_Rewrite
问题描述
我挣扎写.htaccess文件基本上映射以下领域:
I'm struggling writing a .htaccess file to basically map the following domains:
-
dev.domain.com/$1 => index.php文件为/ dev / $ 1
-
api.domain.com/$1 =>的index.php / API / $ 1
-
domain.com/$1 =>的index.php /正面/ $ 1
-
www.domain.com/$1 =>的index.php /正面/ $ 1
dev.domain.com/$1 => index.php/dev/$1
api.domain.com/$1 => index.php/api/$1
domain.com/$1 => index.php/front/$1
www.domain.com/$1 => index.php/front/$1
目前,一切都映射到的index.php / $ 1
,配置如下:
At the moment, everything is mapping to index.php/$1
with the following configuration:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
这是什么来的PHP框架我在默认情况下使用。任何帮助将是pciated :-)大大AP $ P $谢谢!
This is what came with the php framework I'm using by default. Any help would be greatly appreciated :-) Thanks!
推荐答案
如果要映射基于域名请求的路径,那么你可以使用一个额外的的RewriteCond
并匹配 HTTP_HOST
第一。
If you want to map the requested paths based on the domain name, then you can use an additional RewriteCond
and match the HTTP_HOST
first.
您将不得不乘以现有RewriteConds的块和重写规则为每个域 - 除了最后一对其中可能仅仅是一个默认的:
You will have to multiply your block of existing RewriteConds and the RewriteRule for each domain - except for the last pair which could just be a default:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^dev\.domain\.com
RewriteRule ^(.*)$ index.php/dev/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^api\.domain\.com
RewriteRule ^(.*)$ index.php/api/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/front/$1 [L]
未经测试。但也看到在serverfault <一文章href="http://serverfault.com/questions/214512/everything-you-ever-wanted-to-know-about-mod-rewrite-rules-but-were-afraid-to-ask">Everything你曾经想知道的关于mod_rewrite规则,但不敢问?,这也解释了条件之间的相互作用和重写规则。
Not tested. But see also the article on serverfault Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask?, which explains the interactions between conditions and rewrite rules.
这篇关于URL重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!