14100
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
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
RewriteRule ^product/(.*)\.html\??(.*) product.php?productid=$1&$ 2 [qsappend,redirect,last]
>>Also, an attempt to reach:
>>product.php?productid=29 30 -
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
>>product.php?productid=29
you can't do that because it'll create an endless loop -
pruduct.php?productid=2930
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.