2014-10-06 61 views
1
RewriteEngine on 
RewriteCond %{HTTP_HOST} !^www\.example\.com 
RewriteRule (.*) http://www.example.com/$1 [R=301,L] 

# load index.php by default 
DirectoryIndex index.php 

RewriteBase/

# for all other requests load room.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^((?!(index|room)\.php).+)$ room.php?u=$1 [L,NC] 

我的htaccess目前会如果URL包含任何东西,但如果没有它会简单直接到index.phphtaccess的 - 如何不是基于URL模式重定向

的根目录下,如http://www.example.com/anythingelse人重定向到room.php但我需要能够不包含此特定模式的重定向,以便我可以在特定文件夹中创建内容。例如

http://www.example.com/1 
http://www.example.com/2 
http://www.example.com/3 
http://www.example.com/4 

这是可能的吗?

回答

1

您可以在正则表达式模式添加这些排除:

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

# load index.php by default 
DirectoryIndex index.php 

RewriteBase/

# for all other requests load room.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !^/(1|2|3|4) 
RewriteRule ^((?!(index|room)\.php).+)$ room.php?u=$1 [L,NC] 
+0

似乎并不奏效 – 2014-10-06 17:14:27

+0

是'HTTP:// www.example.com/1'仍然要'HTTP:// WWW .example.com的/ room.php?U = 1'? – anubhava 2014-10-06 17:16:41

+0

不,这将是一个实际的目录 – 2014-10-06 17:17:19