apache - htaccess mod_rewrite - Trailing Slash and loop of redirects -


here htaccess code:

rewriteengine on rewriterule ^s/(.*)/(.*) /index.php?search=$1&category=$2 [l,qsa]  rewritecond %{query_string} ^search=([a-za-z0-9\+]+)$ rewriterule ^(.*)$ /s/%1/? [r=301,l]  rewritecond %{query_string} ^search=([a-za-z0-9\+]+)&category=([a-za-z0-9\+]+)$ rewriterule ^(.*)$ /s/%1/%2/? [r=301,l]

i need make rewrite rule this:

http://mywebsite.com/s/query+term => http://mywebsite.com/?search=query+term  or if there category  http://mywebsite.com/s/query+term/category => http://mywebsite.com/?search=query+term&category=category

i need redirect old urls new one.

with rules can obtain have search term , category name joined togheter. in nutshell if had always:
http://mywebsite.com/?search=query+term/category
if remove conditions (rewritecond), leaving rewrite rule addition of trailing slash:

rewriteengine on rewriterule ^s/(.*)/(.*)/ /index.php?search=$1&category=$2 [l,qsa]

reaching url of interest in direct way, whole thing works. not have redirect..

so have tried set rule this:

rewriteengine on rewriterule ^s/(.*)/(.*)/ /index.php?search=$1&category=$2 [l,qsa]  rewritecond %{query_string} ^search=([a-za-z0-9\+]+)$ rewriterule ^(.*)$ /s/%1/? [r=301,l]  rewritecond %{query_string} ^search=([a-za-z0-9\+]+)&category=([a-za-z0-9\+]+)$ rewriterule ^(.*)$ /s/%1/%2/? [r=301,l]

but rule loop of redirects.

you can use following rules :

rewriteengine on  #1--redirect "?search=foobar&cat=cat" "/s/foobar/cat" --# rewritecond %{the_request} /\?search=([^&]+)&cat=([^\s]+) [nc] rewriterule ^ /s/%1/%/%2? [nc,l,r] #2--redirect "/?search=foobar" "/s/foobar" --# rewritecond %{the_request} /\?search=([^/\s]+) [nc] rewriterule ^ /s/%1? [nc,l,r] #1--rewrite "s/foobar/cat" "/?search=foobar&cat=cat"--# rewriterule ^s/([^/]+)/([^/]+)/?$ /?search=$1&$category=$2 [nc,l] #2--rewrite "s/foobar" "/?search=foobar"--# rewriterule ^s/([^/]+)/?$ /?search=$1 [nc,l] 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -