简体   繁体   中英

How can I remove this directory/folder from url with htaccess rewrite?

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.

here is my site:

thewedgiecommunity.x10.mx/wedgiecommunity/

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

  thewedgiecommunity.x10.mx/

But when you click on Community (

 thewedgiecommunity.x10.mx/wedgiecommunity/community.html

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

Would be awesome when someone could help me

You can use this code:

Goes in 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:

RewriteEngine On

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

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

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

Then your other rule will handle the rest.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM