1

I want to redirect my site url's with 301 code

http://www.domain.com/index.php?ms=user&ms_1=name   -->  http://www.domain.com/user/name
http://www.domain.com/index.php?ms=2652&ms_1=title  -->  http://www.domain.com/2652/title
http://www.domain.com/index.php?ms=questions        -->  http://www.domain.com/questions
http://www.domain.com/index.php?ms=aaa&ms_1=bbb&ms_2=ccc      -->  http://www.domain.com/aaa/bbb/ccc

the stuffs after ms can have space and utf8 characters too

How can I do it ?

uchar
  • 2,552
  • 4
  • 29
  • 50

3 Answers3

1

This should work

RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /index\.php\?ms=(.*)&ms_1=(.*)&ms_2=(.*)\ HTTP
RewriteRule ^ /%2/%3/%4\? [R=301,L]
RewriteRule ^(.*)/(.*)/(.*)$ /index.php?ms=$1&ms_1=$2&ms_2=$3 [L]

RewriteCond %{THE_REQUEST} ^(GET|POST)\ /index\.php\?ms=(.*)&ms_1=(.*)\ HTTP
RewriteRule ^ /%2/%3\? [R=301,L]
RewriteRule ^(.*)/(.*)$ /index.php?ms=$1&ms_1=$2 [L]

RewriteCond %{THE_REQUEST} ^(GET|POST)\ /index\.php\?ms=(.*)\ HTTP
RewriteRule ^ /%2\? [R=301,L]
RewriteRule ^(.*)/$ /index.php?ms=$1 [L]

It will change http://www.domain.com/index.php?ms=aaa&ms_1=bbb&ms_2=ccc into http://www.domain.com/aaa/bbb/ccc, but all you to see the content of http://www.domain.com/index.php?ms=aaa&ms_1=bbb&ms_2=ccc etc for the other two links you have.

Howli
  • 12,291
  • 19
  • 47
  • 72
0

I believe you can enable Apache rewrite module and give rewrite rules to do it. It has regex with back-reference ability. A possible (cause I'm not that familiar with regex in rewrite module) ruleset could be :

 ReWriteRule ^/index.php?ms=(.+) /$1
 ReWriteRule ^/index.php?ms=(.+)&ms_1=(.+) /$1/$2
 ReWriteRule ^/index.php?ms=(.+)&ms_1=(.+)&ms_2=(.+) /$1/$2/$3
Scott Chu
  • 972
  • 14
  • 26
0

please follow the code i hope it will be help to you.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?ms=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?ms=$1&ms_1=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?ms=$1&ms_1=$2&ms_2=$3 [L]

befor this code apache rewrite module is enable

piyush patel
  • 191
  • 7