简体   繁体   English

重写-虚拟目录和子域

[英]Rewrite - Virtual Directories and Subdomains

I'm running Apache2 webserver on linux My domain is peku33.net In apache configuration I've set DomainAlias to *.peku33.net 我在Linux上运行Apache2 Web服务器。我的域是peku33.net。在apache配置中,我已将DomainAlias设置为* .peku33.net。

In my public_html directory I have: 在我的public_html目录中,我有:

SomeSite.php
SomeOtherSite.php
SomeotherSiteEtc.php

I want to redirect 我想重定向

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

I also want to disable direct access to theese files (calling http://peku33.net/SomeSite.php will return 304 or 301 code with approperiate Location: ) 我还想禁用对这些文件的直接访问(调用http://peku33.net/SomeSite.php将返回304或301代码,并带有适当的位置:)

Thanks for your replays! 感谢您的重播!

Simple enough, just stick something along the following lines in either a .htaccess file in the document-root directory of your sites (not that efficient as Apache will read and parse the file on every request, also assumes directory Includes have been permitted in the httpd.conf for your sites document root), or preferably in the Virtualhost definition within your Apache's httpd.conf , or associated included .conf : 非常简单,只需将以下内容粘贴到站点文档根目录中的.htaccess文件中即可(效率不高,因为Apache会在每次请求时读取并解析该文件,还假定目录中包括了Includes您网站的文档根目录为httpd.conf ),或者最好是在Apache的httpd.conf中的Virtualhost定义中,或相关的包含的.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]

Note: 注意:

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.

The Apache mod_rewrite documentation is worth a read if your unclear as to what the above rules do, or if you want something a little more abstract consider the following post . 如果您不清楚上述规则的用途,或者如果您想要更抽象的内容,请阅读以下文章 ,这是Apache的mod_rewrite文档的一读。

http://httpd.apache.org/docs/2.2/mod/mod_alias.html#redirect http://httpd.apache.org/docs/2.2/mod/mod_alias.html#redirect

Redirect /SomeSite.php http://peku33.net/SomeOTHERText/

You can add permanent , temp , and seeother for 301, 302, and 303 redirects, respectively. 您可以seeother为301、302和303重定向添加permanenttempseeother

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

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