2012-11-05 85 views
0

我在Linux上运行 Apache2的Web服务器我的域peku33.net 在Apache配置我已经设置DomainAlias为* .peku33.net重写 - 虚拟目录和子

在我的public_html目录,我有:

SomeSite.php 
SomeOtherSite.php 
SomeotherSiteEtc.php 

我想重定向

SomeSite.php -> peku33.net/SomeOTHERText/ 
SomeOtherSite.php -> mysite.peku33.net/SomethingElse/ 
SomeotherSiteEtc.php -> mysubdomain.peku33.net/Blablabla/Blabla/ 

我也想禁用theese直接访问文件(调用http://peku33.net/SomeSite.php将返回304或301与代码的代码位置:)

感谢您的重播!

回答

1

很简单,只要坚持沿着东西在任何一个的.htaccess文件在您的网站(不是有效,因为Apache会读取并解析对每个请求的文件的文档根目录下面的线,还假定目录包括已经在httpd.conf中被允许为您的网站文档根目录),最好在你的Apache的httpd.conf文件虚拟主机定义,或包含相关的.conf

RewriteEngine On 

RewriteCond %{HTTP_HOST)   ^peku33\.net$  [NC] 
RewriteRule ^/?SomeOTHERText/  SomeSite.php   [L] 

RewriteCond %{HTTP_HOST)   ^mysite    [NC] 
RewriteRule ^/?SomethingElse/  SomeOtherSite.php [L] 

RewriteCond %{HTTP_HOST)   ^mysubdomaint  [NC] 
RewriteRule ^/?Blablabla/Blabla/ SomeotherSiteEtc.php [L] 

#Attempt to block direct requests to a .php script, only internally rewritten requests should get through 
RewriteCond %{THE_REQUEST}  SomeSite\.php  [NC] 
RewriteRule ^/?SomeSite.php  -     [F,NC] 

注:

F = Fail (Could use G=Gone or R=### instead) 
NC = Not Case-sensitive 
L = Last 
^/? = optional leading slash, best to leave in place, as the leading slash is stripped from the URI, when the rule is .htaccess based. 

阿帕奇mod_rewrite文档值得一读,如果你不清楚什么上面的规则做,或者如果你想要的东西多一点抽象考虑以下post