htaccess RewriteCond RewriteRule

时间:2013-07-29 03:13:30

标签: apache .htaccess mod-rewrite

我的网站www.example.com位于/ public_html / site。

现在我想将www.example.com/anothersite指向/ public_html / anothersite。

我该怎么办?

/ public_html中的.htaccess:

RewriteOptions inherit

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} !site/
RewriteRule (.*) /site/$1 [L]

/ public_html / site中的.htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /site/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site/index.php [L]
</IfModule>

# END WordPress

在/ public_html的.htaccess中我试过这个,但它说错误404页面找不到!:

RewriteOptions inherit

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

但是我不知道为什么它不起作用,但现在它正在使用上面的代码......

1 个答案:

答案 0 :(得分:0)

/ public_html中的.htaccess:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www.)?example\.com$ [NC]
RewriteRule (?!^(?:site|anothersite)(?:/.*|)$)^.*$ /site%{REQUEST_URI} [L]
相关问题