Reputation: 7038
After asking this question: Clean URLs for search query? I tried something with mod_rewrite:
RewriteCond %{QUERY_STRING} ^s=([a-z]+)$ [NC]
RewriteRule / /s/$1? [NC,R=301,L]
RewriteRule ^s/([a-z]+)$ /?s=$1 [NC,L]
What's the goal?
This looks like double work but if you take a good look you see what I try to accomplish:
If I think about it like this it should be possible. So I would like to seek the help of the experienced mod rewriter to help me out with this one.
Number 2 works but that's it.
Upvotes: 1
Views: 1791
Reputation: 5774
This should work, I tested it with some different names and dirs, but that should be ok in your case.
NB: for matched group from the RewriteCond you must use %1
not $1
.
RewriteCond %{QUERY_STRING} ^s=([a-z]+)$ [NC]
RewriteRule ^$ /s/%1? [NC,R,L]
RewriteRule ^s/([a-z]+)$ /?s=$1 [NC,L]
Edit for debug (see comments) :
my test is :
| /
| --> doc
| |
| --> doc.php (takes doc as GET parameter)
| | index.php
My apache rewrite is
RewriteCond %{QUERY_STRING} ^doc=([a-z]+)$ [NC]
RewriteRule ^$ /doc/%1? [NC,R,L]
RewriteRule ^doc/([a-z]+)$ /doc/doc.php?doc=$1 [NC,L]
Then asking for domain.com/?doc=query displays doc is query
Works for me.
Upvotes: 2