我在linux上运行Apache2 webserver 我的域名是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代码,并附带相应的位置:)
感谢您的重播!
答案 0 :(得分:1)
很简单,只需在站点的document-root目录中的 .htaccess 文件中添加以下行中的内容(效率不高,因为Apache会在每次请求时读取并解析文件) ,还假设您的站点文档根目录 httpd.conf 中允许目录包含,或者最好在Apache的 Virtualhost 定义中。 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,那么Apache post文档是值得一读的。
答案 1 :(得分:0)
http://httpd.apache.org/docs/2.2/mod/mod_alias.html#redirect
Redirect /SomeSite.php http://peku33.net/SomeOTHERText/
您可以分别为301,302和303重定向添加permanent
,temp
和seeother
。