Forum Moderators: phranque
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
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
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 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