首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用.htaccess从url中删除子目录

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

Stack Overflow用户
提问于 2013-05-23 08:59:00
回答 1查看 2K关注 0票数 1

当访问者访问我的站点并阅读帖子时,他们会在地址栏中看到以下内容:

http://www.example.com/darkalfx/?p=71

如何屏蔽url,使其在地址栏中显示以下内容:

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} ^[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]

EN

回答 1

Stack Overflow用户

发布于 2013-05-23 09:43:49

链接:Use htaccess to mask folder name

答案:

代码语言:javascript
复制
    RewriteCond %{THE_REQUEST} ^GET\ /foo/
    RewriteRule ^foo/(.*)$ bar/$1 [R,L]
    RewriteRule ^bar/(.*)$ foo/$1

在您的情况下,^bar将作为主页或prob /I没有.htacess exp

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16704003

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档