Reputation: 329
Here's what I have now:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)(.*)$ /$3?$1=$2 [N,QSA]
This turns www.any.com/x/20/y/30 into www.any.com/index.php?x=20&y=30
(while ignoring existing directories - thank you so much Gumbo!!)
RewriteRule ^([^/]+)/([^/]+)(.*)$ /$3?$1&$2 [N,QSA]
This tweak allows me to go: www.any.com/x/y=30 and accomplish the same results but with x having no value. I love having this option, but I have to do two variables at a time or I get a page not found for the odd variable. So www.any.com/x/y=20/z would give me "url /z not found!"
Any thoughts on how I can get it to rewrite basically every folder into a request variable? Thanks, guys.
Upvotes: 1
Views: 2656
Reputation: 655489
Try these rules:
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([^/=]+)=([^/]*)(/(.+))?$ /$4?$1=$2 [N,QSA]
RewriteRule ^([^/=]+)/([^/=]+)(/(.+))?$ /$4?$1=$2 [N,QSA]
RewriteRule ^([^/=]+)(/(.+))?$ /$3?$1 [N,QSA]
First rule
Is to abort the rewriting process if request can be mapped on an existing file or directory.
Fecond rule
Is for URL paths of the form /foo=bar/…
→ /…?foo=bar
.
Third rule
Is for URL paths of the form /foo/bar/…
→ /…?foo=bar
.
Fourth rule
Is for URL paths of the form /foo/…
→ /…?foo
.
Upvotes: 2