View Full Version : Should I rewrite all link in application for URL Rewrite?
goodmorningsky
09-10-2007, 10:32 PM
Hi, all
http://forums.searchenginewatch.com/showthread.php?t=3925
thread shows url rewrite.
In example
code link: www.example.com/catalog.php?cat=widgets&product_id=1234
link is rewrite to
simple link: www.example.com/catalog/widgets-1234.html
Which means user input simple link, browser address bar shows still simple link but, it actually shows code link contents.
Here, I have a question.
In application there are many code link like
http://forums.searchenginewatch.com/showthread.php?t=3925
or application redirect using code link.
If applcation redirect or user click the link,
does it convert to simple link or just shows code link?
Jazajay
09-28-2007, 01:46 PM
Hi I think I understand what you are trying to say.
If you rewrite a URL you can access it though both the dynamic and static rewrite as in:
RewriteRule ^catalog/widgets-1234.html$ catalog.php?cat=widgts&product_id=1234
would allow you to access the same page though both
http://www.somesite.com/catalog.php?cat=widgts&product_id=1234
www.somesite.com/catalog/widgets-1234.html
However what you want to do is redirect it so as not to get done for duplicate content. You can do this as below -
RewriteRule ^catalog/widgets-1234.html$ catalog.php?cat=widgts&product_id=1234 [R=301,L]
There are other ways of 301ing if you have difficulty with this one.
What this would do is if you typed in or followed a link to
http://www.somesite.com/catalog.php?cat=widgts&product_id=1234
it would redirect to
www.somesite.com/catalog/widgets-1234.html
As in the URL would change in the address bar. This would also pass on any equity, given time, to the rewritten URL.
If this is not what you mean let me know.
goodmorningsky
11-08-2007, 04:46 PM
When I tried the [R=301,L]
It redirect both old url which is reverse way that I want.
I want old url also redirect new simple url.
Jazajay
11-09-2007, 06:29 AM
Ok I think you are saying, correct me if I'm wrong, is that when you type in catalog/widgets-1234.html it redirects you to catalog.php?cat=widgts&product_id=1234, you could try changing the rule around so rather than this-
RewriteRule ^catalog/widgets-1234.html$ catalog.php?cat=widgts&product_id=1234 [R=301,L]
put this in your .htaccess
RewriteRule ^catalog.php?cat=widgts&product_id=1234$ catalog/widgets-1234.html [R=301,L]
If that does not get you the results you can use my preference and that is to 301 on the page. To do that you test the refferer page and if the page is not -
catalog/widgets-1234.html
redirect it to
catalog/widgets-1234.html
via 2 PHP headers,1 to say it's a 301 redirect and another one to reload the page with the right address.
so the second header would look like -
header("www.somesite.com/catalog/widgets-1234.html");
this technically reloads the current page and the first header says that the reload should be classed as a 301.
If you need help implanting the on page version let me know.
Jaza