Page is a not externally linkable
- Code, Content, and Presentation
-- Apache Web Server
---- RewriteRules and .htaccess


lucy24 - 5:45 am on Oct 7, 2011 (gmt 0)


1. Can I simplify the index.html and index.php redirect rules into one rule?

Sure. Use pipes.

##### Resolve index.php, index.html and index.htm to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(index\.php|index\.html?)\ HTTP/
RewriteRule ^index\.php$ http://www.example.com.au/ [R=301,L]

You can make it even a little more concise:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(php|html?)\ HTTP/

2. I also have specific pages which will need to be 301 redirected to a new page. These were originally static html pages. e.g. contact.html, about.html, faq.html etc.... Should I create a separate rule in my htaccess file just for these unique pages (5 in total)?

Just five? Sure, make separate rules. Not worth the trouble of routing to a php fix-up file. But note that your two examples can be merged. And the Condition doesn't seem to be necessary, unless there's something I missed in the earlier posts. Are there circumstances where files named contact.html etc. would not be redirected?

RewriteRule ^(contact|about)\.html?$ http://www.example.com.au/$1-us.html [R=301,L]

3. Finally if my web page name has a space character in it, how would match this in my expression?

e.g. "our services.html"

The situation will not arise, because your web page will not have space characters in it. Unless, ahem, you are talking about pre-existing pages that you are now getting rid of forever and ever.

In htaccess-- unlike generic RegEx-- literal spaces have to be escaped, because the space itself has semantic meaning. Just like you did in your %{THE_REQUEST} condition.

So it would be

our\ services\.html

but only if you swear in blood to get rid of any and all inherited pages whose names were formerly in this form. There have been several recent heated discussions about optimal naming; the preference seems to be a hyphen, as in "our-services.html". Me, I'd just use "services" alone, bypassing the whole issue. Unless you've got another page talking about someone else's services ;)


Thread source:: http://www.webmasterworld.com/apache/4353045.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com