Forum Moderators: phranque

Message Too Old, No Replies

.htaccess problems

change php code instead redirect?

         

Nika

4:33 am on Feb 3, 2005 (gmt 0)

10+ Year Member



Hi,

I have read a lot at this forum about arranging redirects (301) with .htaccess, but got rather confused then before. Neither advise seemed to work for my simple purpose.

My problem is quite traditional: have changed page url names replacing item _shirts_ with _shirt_. Wished to redirect url requests accordingly, since _shirts_ based url worked for some time and ranked high in Google and Yahoo. Quite a typical problem, I guess.

However couldn't use .htaccess for this purpose. Probably because of the fact that my pages are dynamic and rewrite_rule is already applied via .htaccess to make urls spider friendly. Maybe commands I had to apply for mentioned redirect are somewhat specific due to rewrites applied above it in batch.

What I did finally is that I inserted a very simple Logical Check code for the values returned by $_GET for corresponding PHP modules and am changing (before generating html content) every _shirts_ to _shirt_ if url supplies such. As a temporary measure untill new _shirt_ pages get indexed by search engines.

The thing works, of course. But could this be a solution to the problem in general sence. Does anybody know whether there could be any harm from such redirecting as far as search engine ranking is concerned?

Thanks,
Nika

jdMorgan

5:22 am on Feb 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nika,

Welcome to WebmasterWorld!

Changing the URLs on your site to make them search-engine-friendly is always a two-step process.

1) First you change your script to output "friendly" links in the HTML pages it creates.
People see those 'friendly' links and click on them. Search engine robots read those 'friendly' links and follow them. So, both browsers and robots request those 'friendly' URLs from your server.

2) Then you use mod_rewrite to change those friendly URLs (when received in the HTTP requests) back to the format needed to call your script on the server.

The information flow looks like this:

Product_database (unfriendly) -> php_script (change unfriendly to friendly) -> HTML (friendly) -> browser or robot

Visiting person or robot sees the friendly link.

browser or robot (friendly) -> server request -> mod_rewrite (change friendly to unfriendly) -> php script -> database

There is usually no harm done if the method is implemented correctly.

For your purposes, using a URL like /products/shirt or /products-shirt would be better than _shirt_
This is because "_" is recognized as a letter or a full stop by most search engines, whereas "/" and "-" are treated like spaces for the purpose of matching keywords in a URL.

The URL "/this-is/a-string-of-keywords" matches a search for "this is a string of keywords", but the URL "this_is_a_string_of_keywords" matches only a search for "this_is_a_string_of_keywords" -- the search engine treats it as one word!

Jim

Nika

5:53 am on Feb 3, 2005 (gmt 0)

10+ Year Member



Thanks very much, Jim.

The rewriting like you have described I have implemented recently.

However such a crucial difference between _ and - is a true surprise. Though looks obvious now, after I know. As everything...

What about solving redirecting via assigning the same factual url "_shirt_" (beforehand turned "friendly" by rewriting in .htaccess) to incoming urls both "_shirt_" and "_shirts"_ through php may contain a problem as I'm realizing now: spider may "think" I'm duplicating links that point to the same content and may "become upset with my website". Isn't it?

Nika

jdMorgan

6:19 am on Feb 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> (beforehand turned "friendly" by rewriting in .htaccess)

No, your php script should make the 'unfriendly' database entry into a 'friendly' URL, usually using preg-replace.
A browser requests the friendly URL.
The server receives that HTTP request from the browser.
Mod_rewrite changes the 'friendly' URL into a call to your php script, using the 'unfriendly' format.

So the parameters *input* to the script are the same as when it was new and unmodified.

Only the URLs that appear on your pages and are requested by browsers and robots change.

---

Now, in order to 'fix' the search engine problem, we need to differentiate between server-internal rewrites and external redirects.

In order to use search-engine-friendly URLs, you *rewrite* friendly URLs to unfriendly-format script calls. This is done with mod_rewrite. Simple example:


RewriteRule ^products/big-shirt$ /index.php?size=big&product=shirt [L]

In order to remove the old URLs from search engine listings, you *redirect* from the old URL to the new URL. This should be a 301-Moved Permanently redirect. You can do this with mod_rewrite or with your script. Example:

RewriteRule ^products/big-shir[b]ts$[/b] http://www.example.com/products/big-shi[b]rt[/b] [R=301,L]

Jim

Nika

10:26 pm on Feb 3, 2005 (gmt 0)

10+ Year Member



Well,

You have very apprehensible manner of explaining things. Many thanks.

Now it worked fine.

Before I was stuck at point where *RewriteRule ^products/big-shirt$ /index.php?size=big&product=shirt [L]* has been implemented but I just couldn't find the right .htaccess script to make further redirect of *shirts* to *shirt*. Therefore I was doing this at php level checking incoming urls and transforming the return of $_GET into *shirt* if needed. When you saying "You can do this with mod_rewrite or with your script" do you mean something like this mentioning *script*? I feared robot could have considered that as like I'm creating phoney *shirts* pages which point then after to the same page as *shirt* does - duplicating urls that point to same page, in other words.

I'm just trying to understand. Although I used your prompting about *301-Moved Permanently redirect* and made it work.

Thanks

jdMorgan

9:48 pm on Feb 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> I feared robot could have considered that as like I'm creating phoney *shirts* pages which point then after to the same page as *shirt* does - duplicating urls that point to same page, in other words.

If you use a 301-Moved Permanently redirect, there is no phoney page at all. You are telling the search engine robot that the URL has permanently changed. You are telling it to stop using the original URL, and start using the new URL provided in the 301 redirect response.

Also, there is no requirement that a URL (visible on the Web) have any relationship to the filename on the server, and internal rewrites are not visible to anyone except the Webmaster.

As far as duplicate content or 'phoney files" are concerned, don't worry about the 301 redirect.

Jim

Nika

11:55 pm on Feb 4, 2005 (gmt 0)

10+ Year Member



Yeeh, thanks.

I just forgot to mention that I have some number of leftover internal links within the website - all based on old *shirts* version. And they do represent pages to robots and point to same actual content due to redirecting. That's what I meant. I have to change all old named links to new names, I guess.

Thanks again.