如何使用 htaccess 重写从 url 中删除此目录/文件夹? [英] How can I remove this directory/folder from url with htaccess rewrite?
问题描述
我的目标是:
domain.com/folder
重写->
domain.com
这将涉及该站点内的所有链接.我的意思是网站上的链接如下:
this shall concern ALL links inside that site. I mean on the site are links like:
domain.com/folder/forum.html
domain.com/folder/community.html
等
这是我的目标:
domain.com/forum.html
domain.com/community.html
等
非常重要的是,文件夹"永远不会出现在地址栏中的 url 中.
and its very important that the "folder" is never in the url in the adressbar visible.
我已经尝试了很多代码,但我无法真正解决这个问题.我最好的尝试是使用此代码:
I tried already many codes but I couldnt really solve this problem. My best try was with this code:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(.*)folder
RewriteRule ^(.*)$ folder/$1 [L]
如果我输入
domain.com
我得到了
domain.com/folder
显示,什么是正确的(文件夹"不在显示的网址中).但是当我点击网站的一些链接时,比如:domain.com/folder/community.html 然后我可以在 url 中再次看到文件夹",但我希望它总是被删除.
displayed, what is correct ("folder" is not in the url shown). But when i click on some links of the site like: domain.com/folder/community.html then I can see again "folder" in the url, but I want that it becomes ALWAYS removed.
这是我的网站:
thewedgiecommunity.x10.mx/wedgiecommunity/
我的目标是删除wedgiecommunity"(=文件夹)此链接有效
My aim is to remove the "wedgiecommunity" (=folder) This link is working
thewedgiecommunity.x10.mx/
但是当你点击社区(
thewedgiecommunity.x10.mx/wedgiecommunity/community.html
) 然后我在 URL 中再次得到wedgiecommunity".
) then i get again "wedgiecommunity" in the URL.
如果有人可以帮助我就好了
Would be awesome when someone could help me
推荐答案
您可以使用以下代码:
进入 DOCUMENT_ROOT/wedgiecommunity/.htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}s/+wedgiecommunity([^s]*) [NC]
RewriteRule ^ %1 [R=301,L]
进入 DOCUMENT_ROOT/.htaccess:
RewriteEngine On
RewriteRule !^/?wedgiecommunity wedgiecommunity%{REQUEST_URI} [L,NC]
这篇关于如何使用 htaccess 重写从 url 中删除此目录/文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!