简体   繁体   English

htaccess规则从子域重定向,但保持某些文件可访问

[英]htaccess rule to redirect from subdomains but keep some files accessible

<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
AddType application/x-httpd-php .htm .xml .rss
Options Indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{REQUEST_URI} !index\.php
RewriteCond %{HTTP_HOST} ^(.+?)\.mysite\.net$
RewriteRule .* /index.php?sitename=%1 [L]

Options +FollowSymLinks

Thas how my htaccess files looks like. 这是我的htaccess文件的样子。 I want all subdomain.mysite.com to redirect to my index file with the name of the subdomain so i can show the appropriate site. 我希望所有subdomain.mysite.com重定向到带有子域名称的索引文件,以便我可以显示适当的站点。 Thats working fine, so far... 到目前为止,效果还不错...

My problem is that i now need to access for example www.mysite.com/script.php directly and i am getting a 500 error. 我的问题是,我现在需要直接访问例如www.mysite.com/script.php,并且出现500错误。 htaccess is very confusing to me, how would i achieve this? htaccess对我来说很混乱,我将如何实现呢? Thanks! 谢谢!

You need to add these 3 lines to your existing rules: 您需要将这3行添加到现有规则中:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

So the final rules would look like this: 因此最终规则如下所示:

<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
AddType application/x-httpd-php .htm .xml .rss
Options Indexes
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{REQUEST_URI} !index\.php
RewriteCond %{HTTP_HOST} ^(.+?)\.mysite\.net$
RewriteRule .* /index.php?sitename=%1 [L]

Options +FollowSymLinks

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM