簡體   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