Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 466
Bardock Avatar asked Oct 15 '13 19:10

Bardock


1 Answers

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]
like image 178
anubhava Avatar answered Oct 04 '22 00:10

anubhava