Quick htaccess question
-
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.
-
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
-
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]
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
How does Quick View windows affect SEO?
I have the following website that I am building (http://www.jetabout.ca/cruises/). All the items listed link to quick view pop ups. I was wondering how does this affect SEO and will Google be able to pick up on this?
Intermediate & Advanced SEO | | cholidays0 -
Specific KW question...
Hi, I have this site: http://www.aerlawgroup.com. It's ranking very well overall for all targeted KWs. However, I have seen a drop for one main KW: "Los Angeles criminal defense attorney." It currently ranks #8 (it used to be as high as #2). What's interesting is that for similar (yet slightly less competitive KWs, he ranks much better - "Los Angeles Criminal Defense Lawyer." I'm not trying to be greedy with rankings, but I would love feedback and/or tips regarding any issues that could be contributing to this drop. Thanks.
Intermediate & Advanced SEO | | mrodriguez14400 -
Newly Acquired Website--Questions on Changing Permalink Structure
I just acquired a new website. The domain is about 7 years old with around 1000 indexed pages in google. Decent domain authority at 34, PR 4, a lot of inbound links. The thing that's driving me crazy is the permalink structure--set up as month/post name in wordpress http://xxxxxxx.com/2015/01/sample-post/ Based on my experience and I could be wrong, but I would think that the structure would be more effective with just post name and no date. Am I absolutely insane at this point to try and change it?
Intermediate & Advanced SEO | | tryfantasy0 -
How to get a page re-crawed quickly
Does anyone know a way to get Google to re-crawl a webpage that does not belong to me. There are a bunch of pages that I have had links removed on and I want Google to re-crawl those pages to see the links have been removed. (current wait time is way way too long) Can anyone suggest some ways to get the page re-crawled. (I am unable to get the website owners to use WMT to do anything). Suggestions like good ping services and various other techniques would be very much appreciated. Thanks
Intermediate & Advanced SEO | | gazzerman10 -
Summarize your question.Irrelevant Domain Name, relevant page name
Hello All, My website is a PC Repair website called 'Paulspcrepair.co.uk' (example). And recently I want to start my SEO branch to the website, now, would it be better : A: Use my domain Authority already obtained and create a new page, highly optimized for SEO searches. OR B: Create a whole new website, such as 'PaulsSEOWorkshop.co.uk'. If so, why? I can't decide what to try.
Intermediate & Advanced SEO | | Paul_Tovey0 -
Question about HTTP Vary for Mobile
I'm reviewing https://developers.google.com/webmasters/smartphone-sites/redirects, and wondering where exactly to add HTTP Vary: Desktop request which has a mobile page to add “Vary: User-Agent” to the response HEADER Or if the request came from mobile device, than add “Vary: User-Agent” to the response HEADER
Intermediate & Advanced SEO | | nicole.healthline0 -
Anyone have an hour right now to cover some SEO questions
Hi folks, I need someone to Skype with me today, on some seo questions, for a multi wordpress set up I`m in middle of developing for franchise local sites. Will pay you $95 for the hour. Thanks Brent Sky pe me: cyberbrent (Brent H, Richmond, BC)
Intermediate & Advanced SEO | | MenInKilts1 -
301 Redirect using rewrite rule in .htaccess
Hi guys, I have these types of URLs with the format below that are seen as duplicate contents http://www.mysite.com/index.php?a=11&b=15&d=3&c=1 I wanted to permanently redirect them to my homepage. I am thinking if this is possible in .htaccess using rewrite conditions? Thanks in advance...
Intermediate & Advanced SEO | | Trigun0