views:

26

answers:

1

I moved my site to different server since then my all urls started showing up 404 error.

earlier my all urls were like this mysite.com/title-of-url

but now all such urls are getting 404 error, so i disabled seo friendly url feature on site admin and now i can access same page on mysite.com/index.php/title-of-url

i tired to create some regex for .htaccess to do purpose like RewriteRule ^([^/.]+)/?$ /index.php/$1 [L]

but its working fine one depth of "/", i mean its working for mysite.com/first but not for mysite.com/first/second

I am looking for REGEX help regardng it so that mysite.com/first/second should gets rewritten to mysite.com/index.php/first/second as well as mysite.com/something gets rewritten to mysite.com/index.php/something..

looking forward for your kind help Thanks

+1  A: 

Of course it doesn't work with more /. Your rule says:

  • Match from beginning: ^
  • (start grouping for $1: ()
  • Match everything except the slash: [^/]+
  • (end grouping: ))
  • Match an optional leading slash /?
  • Match to the end $

If you really want to match everything, use a dot instead of a character class, matching everything except the /:

RewriteRule ^(.+?)/?$ /index.php/$1 [L]

Do not forget to include a RewriteCond before it excluding existing files and directories, to avoid an infinite recursion. Fail to do this, and you'll end up with a 500 Internal Server Error. Complete code:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ /index.php/$1 [L]
Lekensteyn
Thanks for your input Lekensteyn But i used RewriteRule ^(.+?)/?$ /index.php/$1 [L]as mentioned by you and it ended up in 500 internal server error :(
vaibhav
Is it possible for a regex to rewrite ^mysite.com/depth1/depth2 to ^mysite.com/index.php/depth1/depth2as well as ^mysite.com/depth1 to ^mysite.com/index.php/depth1 in a single rewrite rule.I think if we rewrite mysite.com/somethingsomething to mysite.com/index.php/somethingsomething
vaibhav
Any more help please.
vaibhav
Did you include a `RewriteCond` before the `RewriteRule`? See the bottom of my answer.
Lekensteyn
Thanks a lot Lekensteyn it worked :)
vaibhav