如何使用htaccess重写从url中删除此目录/文件夹?

时间:2022-07-18 10:42:36

My aim is:

我的目标是:

domain.com/folder

rewrite ->

重写 - >

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

etc.

等等

This is my aim:

这是我的目标:

domain.com/forum.html
domain.com/community.html

etc.

等等

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]

If I enter

如果我进入

 domain.com 

I get the content of

我得到的内容

 domain.com/folder

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.

显示什么是正确的(“文件夹”不在显示的URL中)。但是,当我点击该网站的一些链接,如:domain.com/folder/community.html然后我可以在网址中再次看到“文件夹”,但我希望它始终被删除。

here is my site:

这是我的网站:

thewedgiecommunity.x10.mx/wedgiecommunity/

My aim is to remove the "wedgiecommunity" (=folder) This link is working

我的目的是删除“wedgiecommunity”(=文件夹)此链接正常工作

  thewedgiecommunity.x10.mx/

But when you click on Community (

但是当你点击社区(

 thewedgiecommunity.x10.mx/wedgiecommunity/community.html

) then i get again "wedgiecommunity" in the URL.

)然后我再次在URL中“wedgiecommunity”。

Would be awesome when someone could help me

当有人能帮助我时会很棒

2 个解决方案

#1


7  

You can use this code:

您可以使用此代码:

Goes in DOCUMENT_ROOT/wedgiecommunity/.htaccess:

进入DOCUMENT_ROOT / wedgiecommunity / .htaccess:

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+wedgiecommunity([^\s]*) [NC]
RewriteRule ^ %1 [R=301,L]

Goes in DOCUMENT_ROOT/.htaccess:

进入DOCUMENT_ROOT / .htaccess:

RewriteEngine On

RewriteRule !^/?wedgiecommunity wedgiecommunity%{REQUEST_URI} [L,NC]

#2


1  

You can use this rule to "remove" the folder from the URL when it is accessed directly via the browser:

当通过浏览器直接访问该文件夹时,您可以使用此规则从URL中“删除”该文件夹:

RewriteCond %{THE_REQUEST} \ /wedgiecommunity/
RewriteRule ^wedgiecommunity/(.*)$ /$1 [L,R=301]

Then your other rule will handle the rest.

然后你的另一条规则将处理其余的规则。

#1


7  

You can use this code:

您可以使用此代码:

Goes in DOCUMENT_ROOT/wedgiecommunity/.htaccess:

进入DOCUMENT_ROOT / wedgiecommunity / .htaccess:

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+wedgiecommunity([^\s]*) [NC]
RewriteRule ^ %1 [R=301,L]

Goes in DOCUMENT_ROOT/.htaccess:

进入DOCUMENT_ROOT / .htaccess:

RewriteEngine On

RewriteRule !^/?wedgiecommunity wedgiecommunity%{REQUEST_URI} [L,NC]

#2


1  

You can use this rule to "remove" the folder from the URL when it is accessed directly via the browser:

当通过浏览器直接访问该文件夹时,您可以使用此规则从URL中“删除”该文件夹:

RewriteCond %{THE_REQUEST} \ /wedgiecommunity/
RewriteRule ^wedgiecommunity/(.*)$ /$1 [L,R=301]

Then your other rule will handle the rest.

然后你的另一条规则将处理其余的规则。