Forum Moderators: phranque

Message Too Old, No Replies

.htaccess redirect help

.htaccess redirect

         

bpatrick

11:14 am on Aug 17, 2009 (gmt 0)

10+ Year Member



Hi,

I had some of my urls indexed in google search engine incorrectly. For example google indexed this url

[somedomain.com...]

when correct url was

[somedomain.com...]

When visitors click on these incorrect urls they are taken to the home page instead of the category page.

How can I setup a redirect on my htaccess file for all urls ending with the pattern /category/(*.)/$ to /category/(*.)/index.html

Thanks
Patrick

jdMorgan

3:00 pm on Aug 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Patrick, and welcome to WebmasterWorld!

Best practices actually indicate that you should do the reverse: Link to "/" only instead of "/index.xyz" and then redirect any existing inbound "index.html" links (from other websites outside of your control) to "/".

As an example, do you search on www.google.com/ or do you go to www.google.com/index.py (which is the
'real' internal filepath at google)?

Basically, there is no reason to 'reveal' your internal site technology and filepaths to clients; Doing so make your URLs harder for users and other Webmasters to type correctly, harder to remember, dilutes the "branding" of your URLs, and sets you up for rank-passing problems should you ever wish to change to a different technology and retain the "file extension" in the URL.

So most Webmasters these days are asking how to remove file extensions from URLs, rather than asking about how to add them. It's a popular subject in this forum.

However, I will answer your question even though I think that implementing this is ill-advised:

If all category pages are numeric, then the RewriteRule pattern for use in example.com/.htaccess would be ^(category/[0-9]+)/$ and the substitution would be http://www.example.com/$1/index.html with the rule flags "[R=301,L]"

See the resources cited in our Apache Forum Charter, the example threads in our Forum Library, and try a search for previous threads on this subject. Links to all of these features are at the top of this page.

Jim

bpatrick

3:27 pm on Aug 17, 2009 (gmt 0)

10+ Year Member



Thanks Jim.

If I setup the urls
www.example.com/category/123/
and
www.example.com/category/123/index.html
to display the same page does it affect the page rank in anyway?

Patrick

jdMorgan

5:22 pm on Aug 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For each page on your site, one and only one URL should be able to access it directly. All other variations, to include protocol, (sub)domain, port number, URL-path, query string, and character-case variations should be redirected to this single 'canonical' URL.

To allow otherwise creates 'duplicate content' -- essentially causing two or more URLs to compete with each other for links and ranking.

Search engines index URLs -- not pages, and not domains, "web sites," or files, only URLs. The same content appearing for multiple URLs constitutes 'duplicate content' -- a very popular subject in our Google forum.

The usual approach to index pages is to link only to "/" or to "/subdirectory/" from your own pages and then to use

 DirectoryIndex index.html

to internally map URL-path "/" to filepath "/index.html" and to map URL_path "/subdirectory/" to filepath "/subdirectory/index.html", etc.

Having done that, you can detect direct client requests for "/index.html" and redirect them to "/" to force canonicalization of old links. This step alone is not sufficient without the previous steps, and is a bit more complex than may sound (note the italics). But we have many example threads on that subject here.

Jim