Link to home
Start Free TrialLog in
Avatar of 14100
14100Flag for United States of America

asked on

SEO implementation, using htaccess (rewrite), php, regex?

I'm working with a script, where regex will be used to turn all urls of a certain format, into SEO-friendly urls.
i.e.-
product.php?productid=2930
becomes
product/2930.html   (though this will eventually show the actual product name, but that's later...)

I need htaccess rules that could match:
product/2930.html
and map it to the original url.

Also, an attempt to reach:
product.php?productid=2930
should redirect to the new SEO url.


There's one more catch, if there are additional variables in the url, I need a suggestion on how to capture those additional variables and pass them to the SEO url (this is optional, not required to win the points). i.e. - product.php?productid=2930&cat=252
Avatar of m1tk4
m1tk4
Flag of United States of America image

RewriteRule ^product/(.*)\.html\??(.*) product.php?productid=$1&$2 [qsappend,redirect,last]
>>Also, an attempt to reach:
>>product.php?productid=2930 -

you can't do that because it'll create an endless loop -

pruduct.php?productid=2930 redirects to product/2930.html, which redirects to product.php?productid=2930
Avatar of 14100

ASKER

Hmm... then is there no way that you know of, to ensure that the html url is the only one used? I need to maintain backwards compatibility with urls that already have propagated on the web, so if someone the old url structure, they need to be shown the new url.
the backwards compatibility is there, since all your old urls still work.

What you could do is analyze _SERVER['REQUEST_URI'] in your php and send a redirect header() there, it's just you can't really do both redirects in mod_rewrite.
ASKER CERTIFIED SOLUTION
Avatar of caterham_www
caterham_www
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial