Htaccess (without redirecting) [REWRITEURL] (folder to index.php)

I just want to get htaccess fast redirect. i.e:

domain.com/subfolderGreen → domain.com/index.php?folder=subfolderGreen

(note that the Green subfolder actually exists)

I tried, but could not get the desired regular expression.

thanks. a.

ADDED:

Sorry, I want this to work for any subfolder, not just for "subfolderGreen" I use

RewriteRule ^ / ([^ /] +) /? $ / index.php? folder = $ 1 [L]

but it does not work. any clues?

+4
source share
4 answers

I would think that your example would cause an infinite loop, since /index.php matches what you are doing. Try the following:

RewriteRule ^([A-Za-z0-9]+)/?$ /index.php?folder=$1 [L] 

If you want it to work for all existing directories, this will probably work as well.

 RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.+)/?$ /index.php?folder=$1 [L] 
+2
source
 RewriteRule ([^/]+)$ index.php?folder=$1 

I think this will do the trick.

RewriteRule has some confusing issues when used in .htaccess, which requires the addition of a RewriteBase.

What errors / problems do you see? If you want to be sure how redirecting the addition of [R] can often help with debugging.

Finally ... does the Green subfolder really exist or not? If it exists, it can cause some problems.

+1
source

I believe this:

 RedirectMatch 301 domain.com/(.*) domain.com/index.php?folder=$1 
0
source
 RewriteEngine on RewriteCond %{THE_REQUEST} ^[AZ]+\ /(([^/\ ]+/)*)/+([^\ ]*) RewriteRule ^ /%1%3 [L,R=301] RewriteRule ^([^/]+)/?$ index.php?folder=$1 [L] 

Line No. 2 will handle the case if someone goes to website.com/mypage/////, so he defaults to website.com/mypage/(I think)

-1
source

All Articles