SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2012
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Search Engine Questions

    I have the following code in my .htaccess file, to omit the file extension .php in the url for each file:

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

    Right now, I have pages in the search engine show up with both the .php and without. How can I make sure it will show up without?
    Also, I have two more problems.
    How can I make sure the search engines only display my site without the www?
    How can I make sure the search engines display http://mysite.com instead of http://mysite.com/index or http://mysite.com/index.php

    Thanks!

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,620
    Mentioned
    413 Post(s)
    Tagged
    7 Thread(s)
    Quote Originally Posted by andywhizwang View Post
    How can I make sure the search engines only display my site without the www?
    Try this:

    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^mysite\.com$ [NC]
    RewriteRule .? http://mysite.com%{REQUEST_URI} [R=301,L]
    (Obvioulsy you don't need to repeat the first line if you have it already.)

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    andy,

    Ralph got the second part correct, just use the same flags on the first part which looks fine at your end. The 301 redirection will tell the SE's to make that a permanent redirection and update their records.

    Thanks, Ralph!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2012
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay- I've got the www part.
    How do I make sure that the search engines only display mysite.com instead of mysite.com/index.php.
    Also, how do I make sure that the search engines display mysite.com/page_name instead of mysite.com/page_name.php?
    Thanks!

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    aww,

    www is easy, I'd not worry about the index.php (except to remove the extension) and removing the extensions will be picked-up by SE's with 301's on their link redirections.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •