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

时间:2013-05-23 00:59:00

标签: wordpress apache .htaccess masking

当访问者访问我的网站并阅读帖子时,他们会在地址栏中看到此信息:
http://www.example.com/darkalfx/?p=71

如何屏蔽网址,使其在地址栏中显示:
http://www.example.com/?p=71

基本上我只是希望在子目录中的任何页面显示而不是网址中的/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} ^[A-Z]{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} ^[A-Z]{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} ^[A-Z]{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]

1 个答案:

答案 0 :(得分:0)

链接: Use htaccess to mask folder name

答案:

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

在你的情况下^酒吧将是家或prob / 我没有.htacess exp