Removing file extensions in htaccess

Category: Cpanel

MtnBeachBum
Asked:
2012-06-08 1:41 pm EST

Hits: 1,241
I think I have finally figured out how to get pretty urls; www.mysite.com/about.html is showing mysite.com/about. So i think I have the htaccess file correct. My question is that Google and Bing still show all urls with .html extension. I think I have to redirect old .html sites to new urls but couldn't get it to work last night. Can anyone help me with this? I resubmitted site under new url to both Google and Bing, but i think i will still have to redirect?

Thanks

You must login before you can ask a follow up question.

You must login before you can submit an answer.

OTHER ANSWERS

0

Scott
Staff
17,111 Points
2012-06-08 2:30 pm EST
Hello MtnBeachBum,

You were on the right track, but the htaccess needed a bit of tweaking. I saved the original for you as .htaccess1 and the .htaccess file running is the modified one.

I replaced that bit of rewrite code with the following code:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.html
RewriteRule (.*)\.html$ /$1 [L,R=301]

This allows the mysite.com/about to display even if the user types in mysite.com/about.html and the Search engines redirect properly now as well.

I hope this answers your question. If you have any more questions or information specific to the issue please leave a comment below so we can further assist you.

Best Regards,
Scott M

You must login before you can post a comment about this answer.

How do you use the code above but force trailing slashes?
kfarrell
9 Points
2013-08-25 11:53 am EST
Actually, I tried the code above in my site, and I get a 500 error. I have tried several rules (for about 2 hours), and I keep getting 500 errors. I think some other rules are clashing with the new ones I have tried. I have a lot of rewrite rules in my .htaccess file because I recently updated my site, and I changed the names of several files. I don't know if that is the problem or not. The site is alvingolf.com, and I'm on an inmotionhosting.com VPS.
kfarrell
9 Points
2013-08-25 12:04 pm EST
Hello Kfarrell,

If you have multiple re-write rules, they are read and applied in the order they are stored in the .htaccess file. If you want to try to see if the rule properly works, try making this the first rule and comment or remove the other rules AFTER you have made a backup of the file. Then you can see if the rule is working since it will not conflict with the other rules.

I did take a quick peek at your .htaccess file but I did not see the above rule included. Please try this first and then let us know if the issue is resolved or not.

Apologies for the troubles with the rules. Please try the recommendation above first, and then let us know if you continue have any issues that require further assistance.

Kindest regards,
Arnel C.

Arn
16,201 Points
Staff
2013-08-26 5:51 pm EST
Like this Question?

Related Articles

It looks like there are no related articles.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!