0

我在根文件夹中有站点www_root/www.examle.com

.htaccess

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

我也在subdomain.example.com文件夹中有子域www_root/subdomain。还有.htaccess

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

如果我在浏览器中输入www.example.com/subdomain- wokring 但如果我输入 URL 之类的subdomain.example.com- 不起作用(仅主页)

请帮忙,我做错了什么。

谢谢。

4

1 回答 1

0

您尝试将 apacheVirtualHost功能替换为mod_rewrite. 这是可能的,但不是最理想的。考虑VirtualHostsubdomain.example.com

如果您出于某种原因坚持使用mod_rewrite,您可以在根文件夹中进行这样的配置.htaccess(您应该.htaccesssubdomain文件夹中删除或移动):

RewriteEngine on

# normalization of hostname
RewriteCond %{HTTP_HOST} =example.com [NC]
RewriteRule ^(.*)$ http://www.examle.com/$1 [R=301,L]

# config for www.example.com
RewriteCond %{HTTP_HOST} =www.example.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

# config for subdomain.example.com
RewriteCond %{HTTP_HOST} =subdomain.example.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ subdomain/index.php?q=$1 [L,QSA]

...但同样,VirtualHost这是更好的解决方案。

于 2012-12-07T17:19:38.237 回答