.htaccess: Redirect user to specific page if he accesses directory

I'm currently working on ironing out some little problems with my website and prep it for SEO a little bit. I followed Google's SEO Optimization guide and found this quote:

Consider what happens when a user removes part of your URL - Some users might navigate your site in odd ways, and you should anticipate this. For example, instead of using the breadcrumb links on the page, a user might drop off a part of the URL in the hopes of finding more general content. He or she might be visiting http:// www.brandonsbaseballcards.com/news/010/upcoming-baseballcard-shows.htm, but then enter http://www.brandonsbaseballcards.com/news/010/ into the browser's address bar, believing that this will show all news from 010. Is your site prepared to show content in this situation...?

Well, currently my site is not prepared for this situation and would direct the user to a directory or a 404 page.

I searched on the web for a little bit and found this and this link which seem to go into the right direction but I wasn't quite sure. Ideally, I would like to try this out on localhost (XAMPP) before I upload the page.

So my question would be, how would I redirect (through htaccess) a user who puts in, say, http://www.example.com/baseballcards to http://www.example/baseballcards/all.html?

Thank you very much!

Answers


Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^(baseballcards)/?$ /$1/all.html [L,NC]

Above rule will internally forward /baseballcards to /baseballcards/all.html but won't change the URL in the browser (external redirect). If you want external redirection then use following rule:

RewriteRule ^(baseballcards)/?$ /$1/all.html [R=301,L,NC]

Need Your Help

RoR: testing an action that uses http token authentication

ruby-on-rails testing rspec2

I'm trying to test a controller that's using an http token authentication in the before filter. My problem is that it works ok wheh I use curl to pass the token, but in my tests it always fails (I'm

navigate into wrong tab when refresh the page

javascript html

I have a page that has two main tabs, devices and reports. Every time I refresh the page, the page display the information for reports(suppose to display the info for the devices). This also applie...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.