繁体   English   中英

如何使用.htaccess从网址中删除子目录

[英]How to remove subdirectory from url using .htaccess

访客访问我的网站并阅读帖子时,他们会在地址栏中看到以下内容:
http://www.example.com/darkalfx/?p=71

如何屏蔽网址,以便它在地址栏中显示出来:
http://www.example.com/?p=71

基本上,我只希望显示该子目录中的任何页面,而无需在URL中显示/darkalfx/

这是我到目前为止在.htaccess中拥有的内容
# Externally redirect only direct client requests for /index.php and
# /index.html and /index.htm with /darkalfx to root URL ending with slash.
RewriteCond %{THE_REQUEST} ^[AZ]{3,9}\\ /darkalfx/([^/]+/)*index\\.(html?|php)\\ HTTP/
RewriteRule ^darkalfx/(([^/]+/)*)index.(html?|php)$ http://www.example.com/$1 [R=301,L]

# Externally redirect only direct client requests for /darkalfx<something>
# to www.example.com/<something>.
RewriteCond %{THE_REQUEST} ^[AZ]{3,9}\\ /darkalfx([^\\ ]+)\\ HTTP/
RewriteRule ^darkalfx(.*) http://www.example.com/$1 [R=301,L]

# Externally redirect only direct client requests for /index.php
# and /index.html and /index.htm to URL ending with slash.
RewriteCond %{THE_REQUEST} ^[AZ]{3,9}\\ /([^/]+/)*index\\.(html?|php)\\ HTTP/
RewriteRule ^(([^/]+/)*)index.(html?|php)$ http://www.example.com/$1 [R=301,L]

# Externally redirect to canonicalize the domain name if a non-canonical
# hostname is requested, in order to prevent duplicate-content problems
RewriteCond %{HTTP_HOST} !^(www\\.example\\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

# Internally rewrite requests for www.example.com/<anything>
# to internal server path at /darkalfx/<anything>
RewriteCond %{REQUEST_URI} !^/darkalfx
RewriteRule (.*) /darkalfx/$1 [L]

链接: 使用htaccess屏蔽文件夹名称

回答:

    RewriteCond %{THE_REQUEST} ^GET\ /foo/
    RewriteRule ^foo/(.*)$ bar/$1 [R,L]
    RewriteRule ^bar/(.*)$ foo/$1

在您的情况下,^ bar将会成为家中的一个或概率/我没有.htacess exp

暂无
暂无

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

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