重写到www并重写目录名称

时间:2012-07-29 19:40:20

标签: apache mod-rewrite

嗨我有一些像下面这样的东西,一切都很完美,直到我尝试添加'www'如果它不存在我得到类似下面的东西:

原产地:http://domain.net/welcome/

重写:http://www.domain.net//index.php/?request=welcome

php_value register_globals "on"
RewriteEngine on


RewriteRule ^(.+)/$ /index.php?request=$1

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

RewriteCond %{HTTP_HOST} ^domain.net$
RewriteRule (.*) http://www.domain.net/$1 [R=301]

ErrorDocument 404 /404.php?request=$1

1 个答案:

答案 0 :(得分:0)

尝试将重定向规则移到规则的其余部分之上并添加[L]标志:

php_value register_globals "on"
RewriteEngine on

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

RewriteRule ^(.+)/$ /index.php?request=$1

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

ErrorDocument 404 /404.php?request=$1