The Moz Q&A Forum

    • Forum
    • Questions
    • My Q&A
    • Users
    • Ask the Community

    Welcome to the Q&A Forum

    Browse the forum for helpful insights and fresh discussions about all things SEO.

    1. SEO and Digital Marketing Q&A Forum
    2. Categories
    3. Intermediate & Advanced SEO
    4. Quick htaccess question

    Quick htaccess question

    Intermediate & Advanced SEO
    3 3 130
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as question
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Blink-SEO
      Blink-SEO last edited by

      Hi! I'm trying to do a 301 from www.stevesims.com/index.htm to www.stevesims.com.

      I know I need to use the request command to avoid an infinite loop, but I can't quite figure out the correct code. Here's the first part of the htaccess file.

      RewriteEngine On

      RewriteCond %{HTTP_HOST} ^stevesims.com
      RewriteRule (.*) http://www.stevesims.com/$1 [R=301,L]

      RewriteCond %{HTTP_REFERER} !^http://stevesims.com/.*$ [NC]
      RewriteCond %{HTTP_REFERER} !^http://stevesims.com$ [NC]
      RewriteCond %{HTTP_REFERER} !^http://www.stevesims.com/.*$ [NC]
      RewriteCond %{HTTP_REFERER} !^http://www.stevesims.com$ [NC]
      RewriteRule .*.(jpg|jpeg|gif|png|bmp)$ - [F,NC]

      Any suggestions would be much appreciated.

      1 Reply Last reply Reply Quote 0
      • asmedia
        asmedia last edited by

        This is my code : it redirect all

        mysite.com to www.mysite.com and mysite.com/index.php to mysite.com (need to rename htaccess.txt to .htaccess)

        <ifmodule mod_rewrite.c=""># Redirect non-www to www
        Options +FollowSymLinks
        RewriteEngine On
        RewriteCond %{HTTP_HOST} ^yoursite.com
        RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]</ifmodule>

        RewriteBase /

        RewriteCond %{HTTP_HOST} !^www.

        RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^([^.]+)$ $1.php [NC,L]

        RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)[^.#?\ ]+.php([#?][^\ ])?\ HTTP/
        RewriteRule ^(([^/]+/)*[^.]+).php http://www.yoursite.com/$1 [R=301,L]
        RewriteRule ^index.php$ - [L]

        1 Reply Last reply Reply Quote 0
        • Modi
          Modi last edited by

          Ideally, you should avoid 301 redirect from index.php, as it will cause to go in infinite loop. I too have used 301 redirect earlier, but later applied a better way is Rel=canonical tag

          Still, if you look for 301 redirect - below is the code which will help redirecting :-

          RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.index.html\ HTTP/
          RewriteRule ^(.
          )index.html$ /$1 [R=301,L]

          May also see this url for all sort of redirection from html, php, non www page to www page http://www.gabblet.com/post/2011/09/27/301-redirect-for-index-non-www-to-www-using-htaccess.aspx

          Let know how it goes

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          • Few question about SEO
            Eric_Rohrback
            Eric_Rohrback
            0
            3
            109

          • Htaccess Question - Is this the way to go to consolidate?
            donford
            donford
            0
            6
            88

          • Quick Question: Is it Bad for SEO to paste from Word to your CMS?
            WebMarkets
            WebMarkets
            0
            10
            442

          • Htaccess 301 regex question
            BlueprintMarketing
            BlueprintMarketing
            0
            6
            173

          • Followup question to rand(om) question: Would two different versions (mobile/desktop) on the same URL work well from an SEO perspective and provide a better overall end-user experience?
            retailgeek
            retailgeek
            0
            2
            202

          • .htaccess question/opinion/advice needed
            0
            1
            150

          • 301 redirect via htaccess question
            Audiohype
            Audiohype
            0
            4
            404

          • Architecture questions.
            CleverPhD
            CleverPhD
            0
            10
            1.1k

          Get started with Moz Pro!

          Unlock the power of advanced SEO tools and data-driven insights.

          Start my free trial
          Products
          • Moz Pro
          • Moz Local
          • Moz API
          • Moz Data
          • STAT
          • Product Updates
          Moz Solutions
          • SMB Solutions
          • Agency Solutions
          • Enterprise Solutions
          • Digital Marketers
          Free SEO Tools
          • Domain Authority Checker
          • Link Explorer
          • Keyword Explorer
          • Competitive Research
          • Brand Authority Checker
          • Local Citation Checker
          • MozBar Extension
          • MozCast
          Resources
          • Blog
          • SEO Learning Center
          • Help Hub
          • Beginner's Guide to SEO
          • How-to Guides
          • Moz Academy
          • API Docs
          About Moz
          • About
          • Team
          • Careers
          • Contact
          Why Moz
          • Case Studies
          • Testimonials
          Get Involved
          • Become an Affiliate
          • MozCon
          • Webinars
          • Practical Marketer Series
          • MozPod
          Connect with us

          Contact the Help team

          Join our newsletter
          Moz logo
          © 2021 - 2026 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
          • Accessibility
          • Terms of Use
          • Privacy