Forum Moderators: phranque

Message Too Old, No Replies

Hide extensions in urls and SEO

         

AlonG

1:07 am on Sep 5, 2011 (gmt 0)

10+ Year Member



Hello,

I would like to hide extensions for my urls just like this website:

[jaycutler.com...]


I read that I should use something like this in the htaccess file:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html


Now I got a question regarding google and SEO

As for now, google shows on google search resaults my site urls with .html extension, for example domain.com/contact.html

As mentioned above I would like to use domain.com/contact and hide the extention in my url and search results.

If I do so how will that affect SEO and how will google show my site urls in the search results pages?
Will I lose all the SEO jouice from my old backlinks pointing to me? Do I need to use some kind of 301 redirect?

My site is 1 year old now and is already ranking pretty well for my nich and targeted keywords, I would hate to see a drop.

Please help me,



Thanks!

g1smd

6:08 am on Sep 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



URLs are defined in links out there on the web.

Link to the URL you want users and bots to "see" and "use".

Use a rewrite (using a
RewriteRule
) to fetch the content from the real location inside the server.

Finally, to tidy things up, set up a redirect (using a
RewriteRule
) so that if anything asks for the "wrong" version of the URL the server sends a 301 redirect telling the browser or bot to make a new request for the correct URL.

There are very many previous threads (at least a thousand) with various example code snippets and further explanation right here in this forum.

The code you have shown above is very inefficient. It says "for every request (.*) hitting the server (including requests for images, stylesheets, js scripts, etc), check the hard drive to see if it matches a folder name and then check again to see if it matches a filename, and if it does not, then rewrite the request".

You can make this more efficient by adding a preceding RewriteCond that checks to see that the request doesn't end in various extensions; e.g.
!\.(css|js|png|jpe?g|gif|zip|txt)$
(requests that you are never going to rewrite) or you could change the
(.*)
pattern to be more specific; e.g.
^([0-9a-z]+)$
or
^([^/.]+)$
or similar (so it matches only requests that will be rewritten), and then do away with the slow and inefficient -f and -d "exists" checks completely.

Use example.com here in the forum to suppress auto-linking and leave the code readable.

Failing to add the redirect will leave you with a Duplicate Content problem. Adding the redirect will claim back most of the credit for your incoming links. Over time, the other sites should be asked to update the URL they point to in their link.

AlonG

8:25 am on Sep 5, 2011 (gmt 0)

10+ Year Member



Hey, thakns for your detailed answer. Unfortunately I am not familiar with coding that much and can't really understand how to move forward with your reply. Can you give me directons and copy to paste code to put in my htaccess file? I am a n00b at this.

What I meant with google is that now it shows my website on search resaults with the extensions, and I would like my website to be seen extensionless on search engine resaults and also on my site itself but I don't want to lose all the SEO work I hav purchased in the last year, so all backlinks still stay in place.

Many thanks!

lucy24

8:57 am on Sep 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What's with this sudden mad flurry of rewrite-plus-redirect questions? :) There have been at least three in the past week.
You can make this more efficient by adding a preceding RewriteCond that checks to see that the request doesn't end in various extensions; e.g. !\.(css|js|png|jpe?g|gif|zip|txt)$ (requests that you are never going to rewrite)

I thought that was what the
RewriteCond %{REQUEST_FILENAME}\.html -f 

was for. (Assuming for the sake of discussion that that's a typo missing space.) Keep the \.html, toss the -f.

The google/SEO question is really no different from any other name change. If everything is being redirected from Old Address to New Address, then eventually the new address will replace the old one. The question is what happens in the meantime, and whether you can afford to wait it out. But that's a question for the Google or Search Engines forum.

AlonG

9:20 am on Sep 5, 2011 (gmt 0)

10+ Year Member



Hey again,


I contacted my web hosting provider and gave a link to this thread, and asked him to explain, seems like he is not sure what the right thing is, here is the naswer from hostgator:


Hello Alon,

The following that you have will work:

Options +FollowSymlinks

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html


What the person at the site you linked to is talking about gets a bit more complicated and would look something like what I have pasted below. Essentially he is suggesting that you use more wild-cards as the person feels this will be more efficient.

RewriteRule ^/?about-us/([a-z--]+)$ /about-us/$1\.php

There are a lot of SEO tricks out there and you might check out the following websites for hints [econsultancy.com...] and [zenverse.net...] In reality though what you previously have will work and the re-writes process fast enough it doesn't put any un-necessary strain on the server. I hope these links guide you and please let us know if you have any other questions or need further assistance.

Thank you for choosing HostGator.com, we appreciate your business!

I am so confused now, and don't want to make mistakes!

g1smd

9:29 am on Sep 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The point is that the "-f" forces the server to go off and locate the hard drive, make a request to it to see if a certain file exists, then wait an age for the reply to come back. Since you are never going to rewrite requests for images why bother checking the server to see if the file exists. Simply precede the ruleset with a RewriteCond that says "if this is a request for an image/stylesheet/js file (determined by requested extension in URL request) don't bother with the next few lines, just get on and serve the file.

Once you go truly extensionless you can dispense with large amounts of such clutter from the site configuration files.

Can you give me directons and copy to paste code to put in my htaccess file?

No. For several reasons. There's not enough volunteers here to provide a free code-writing service. Additionally, as I mentioned above, there are more than a thousand previous examples of how to do this right in this forum. You should read several dozen of them and experiment with code on a test server.

I am a n00b at this.
All the more reason why you should learn exactly what the code does and how it works. This is server configuration code. A single typo can put your site offline. You need to know how your code works.

AlonG

9:38 am on Sep 5, 2011 (gmt 0)

10+ Year Member



g1smd, I understand you cannot provide a free code-writing for me, and you already doing a great job. I would like to hire you for this as I don't have the time to deal with this (too busy with work) If you are interested please email me at alongabbay@yahoo.com

Thanks!