Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
846 views
in Technique[技术] by (71.8m points)

regex - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...