Reputation:
I just want to get a quick htaccess redirection. ie:
domain.com/subfolderGreen --> domain.com/index.php?folder=subfolderGreen
(note that the subfolderGreen actually exists)
I've been trying but couldn't get to the regex needed.
thanks. a.
ADDED:
Sorry, i want this to work for any subfolder, not just "subfolderGreen" I'm using
RewriteRule ^/([^/]+)/?$ /index.php?folder=$1 [L]
but it's not working. any clues?
Upvotes: 4
Views: 2835
Reputation: 15111
I would think your example would cause an endless loop since /index.php matches what you are doing. Try this:
RewriteRule ^([A-Za-z0-9]+)/?$ /index.php?folder=$1 [L]
If you want it to work for all directories that exist, this will probably work as well.
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+)/?$ /index.php?folder=$1 [L]
Upvotes: 3
Reputation: 51110
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /(([^/\ ]+/)*)/+([^\ ]*)
RewriteRule ^ /%1%3 [L,R=301]
RewriteRule ^([^/]+)/?$ index.php?folder=$1 [L]
Line #2 will handle the case if someone goes to website.com/mypage///// so it defaults to website.com/mypage/ instead (I think)
Upvotes: -1
Reputation: 14149
RewriteRule ([^/]+)$ index.php?folder=$1
I think that will do the trick.
RewriteRule has some confusing issues when used in .htaccess which requires the addition of a RewriteBase.
What errors/problems are you seeing? If you want to be sure of how it's redirecting adding a [R] can often help with the debugging.
Finally... does the subfolderGreen really exist or not? If it exists that could cause some problems.
Upvotes: 1
Reputation: 284796
I believe it's:
RedirectMatch 301 domain.com/(.*) domain.com/index.php?folder=$1
Upvotes: 0