How to remove this directory / folder from url using htaccess rewrite?

My goal:

domain.com/folder 

rewrite β†’

 domain.com 

this applies to ALL links within this site. I mean, the site has links like:

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

and etc.

It is my goal:

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

and etc.

and it’s very important that the β€œfolder” is never in the URL in the visible host.

I have tried many codes already, but I really could not solve this problem. My best attempt was with this code:

 Options +FollowSymLinks RewriteEngine on RewriteCond %{REQUEST_URI} !(.*)folder RewriteRule ^(.*)$ folder/$1 [L] 

If i introduce

  domain.com 

I get the contents

  domain.com/folder 

which is correct (the "folder" is not listed in the URL shown). But when I click on some site links, for example: domain.com/folder/community.html, then I can again see the "folder" in the URL, but I want it to be deleted ALWAYS.

here is my site:

 thewedgiecommunity.x10.mx/wedgiecommunity/ 

My goal is to remove "wedgiecommunity" (= folder) This link works

  thewedgiecommunity.x10.mx/ 

But when you click "Community" (

  thewedgiecommunity.x10.mx/wedgiecommunity/community.html 

), then again I get "wedgiecommunity" in the url.

It would be great if someone helped me

+6
source share
2 answers

You can use this code:

Going to DOCUMENT_ROOT / wedgiecommunity / .htaccess:

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

Going to DOCUMENT_ROOT / .htaccess:

 RewriteEngine On RewriteRule !^/?wedgiecommunity wedgiecommunity%{REQUEST_URI} [L,NC] 
+7
source

You can use this rule to β€œdelete” a folder from a URL when accessing directly through a browser:

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

Then your other rule will handle the rest.

+1
source

Source: https://habr.com/ru/post/956011/


All Articles