I am not a PHP developer at heart and I have been asked to perform some SEO on an existing PHP website.
The first thing I noticed was the ugly URLs so I want to get these to rewrite to something more informative. Here are all the possible patterns:
/index.php?m=ModuleType&categoryID=id
/index.php?m=ModuleType&categoryID=id&productID=id
/index.php?page=PageType
/index.php?page=PageType&detail=yes
So basically what I want to do is convert these into something like:
/ModuleType/Category
/ModuleType/Category/ProductName
/Page
/Page
I haven't used mod_rewrite before any advice or examples would be great!
Thanks.
I'm not a mod_rewrite expert by any means, but this is an example of how I put together the .htaccess for the Image Flair site:
This basically maps:
and
You should be able to adapt that to your needs, but you may have a couple of issues:
Going on the list of URLs you want, this should work, although I won't claim it's the best or only way to do it :-)
As suggested, you may want to replace the .* with [^/]+ but I had issues with non-matches when I did that, and had no time to troubleshoot, so YMMV :-)
It's not quite clear from your post what the variables are. But assuming that
ModuleType
,id
(x2) andPage
are all variables then the following rules with backreferences should work within a.htaccess
file.The last one didn't really make sense as you've written it. So instead you can add
/detail
on the end.These should slip straight over the top of your existing applications without any modifications to the app. Because they aren't redirecting with
[R]
it will be transparent to your users.mod_rewrite would rather be used to do the opposite: rewrite requests of
/ModuleType/Category/ProductName
internally to/index.php?m=ModuleType&categoryID=id&productID=id
. Using the new URLs in the documents is the job of your application.Edit Here’s an example of how a function might look like that turns your parameterized URLs into the new ones: