.htaccess redirect question
-
Hi guys and girls
Please forgive me for being an apache noob, but I've been trawling for a while now and i can't seem to find a definitive guide for my current scenario.
I've walked into a but of a cluster$%*! of a job, to rescue a horribly set up site. One of many, many problems is that they have 132 302redirects set up. Some of these are identical pages but http-https, others are the same but https-http and some are redirects to different content pages with http-http.
A uniform redirecting of http to https is not an option so I'm looking to find out the best practice for reconfiguring these 302s to 301s within .htaccess?
Thanks in advance
-
Does the site even need HTTPS? If not, just delete all the rules sending it back and forth, and create a 301 for each https to go to http. You could probably knock out all 132 in less than 2 hours. (I have done 100 in less than 45 mins ;))
"A uniform redirecting of http to https is not an option so I'm looking to find out the best practice for reconfiguring these 302s to 301s within .htaccess?"
Yes, you can do a sitewide redirect to send all URL's to the secure version.
http://www.besthostratings.com/articles/force-ssl-htaccess.htmlI agree with you tho, that htaccess is a mess lol. If that is any indication of what the rest of the site has in store for you, whew.
-
Hi Jane, many thanks for getting back to me.
I do indeed have access to the existing .htaccess file...
Apache/PHP/Drupal settings:
Protect files and directories from prying eyes.
<filesmatch ".(engine|inc|info|install|make|module|profile|test|po|sh|.sql|theme|tpl(.php)?|xtmpl|svn-base)$|^(code-style.pl|entries.|repository|root|tag|template|all-wcprops|entries|format)$"="">Order allow,deny</filesmatch>
Don't show directory listings for URLs which map to a directory.
Options -Indexes
Follow symbolic links in this directory.
Options +FollowSymLinks
Make Drupal handle any 404 errors.
ErrorDocument 404 /index.php
Force simple error message for requests for non-existent favicon.ico.
<files favicon.ico=""># There is no end quote below, for compatibility with Apache 1.3.
ErrorDocument 404 "The requested file favicon.ico was not found.</files>Set the default handler.
DirectoryIndex index.php
Override PHP settings. More in sites/default/settings.php
but the following cannot be changed at runtime.
PHP 4, Apache 1.
<ifmodule mod_php4.c="">php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0</ifmodule>PHP 4, Apache 2.
<ifmodule sapi_apache2.c="">php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0</ifmodule>PHP 5, Apache 1 and 2.
<ifmodule mod_php5.c="">php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0</ifmodule>Requires mod_expires to be enabled.
<ifmodule mod_expires.c=""># Enable expirations.
ExpiresActive On</ifmodule>Cache all files for 2 weeks after access (A).
ExpiresDefault A1209600
<filesmatch .php$=""># Do not allow PHP scripts to be cached unless they explicitly send cache
headers themselves. Otherwise all scripts would have to overwrite the
headers set by mod_expires if they want another caching behavior. This may
fail if an error occurs early in the bootstrap process, and it may cause
problems if a non-Drupal PHP file is installed in a subdirectory.
ExpiresActive Off</filesmatch>
#pagespeed modifications
<files *.js.gz="">AddEncoding gzip .js
ForceType application/x-javascript</files>
<files *.css.gz="">AddEncoding gzip .css
ForceType text/css</files>Various rewrite rules.
<ifmodule mod_rewrite.c="">RewriteEngine on</ifmodule>
RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
If your site can be accessed both with and without the 'www.' prefix, you
can use one of the following settings to redirect users to your preferred
URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
To redirect all users to access the site WITH the 'www.' prefix,
(http://example.com/... will be redirected to http://www.example.com/...)
adapt and uncomment the following:
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
To redirect all users to access the site WITHOUT the 'www.' prefix,
(http://www.example.com/... will be redirected to http://example.com/...)
uncomment and adapt the following:
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
Modify the RewriteBase if you are using Drupal in a subdirectory or in a
VirtualDocumentRoot and the rewrite rules are not working properly.
For example if your site is at http://example.com/drupal uncomment and
modify the following line:
RewriteBase /
If your site is running in a VirtualDocumentRoot at http://example.com/,
uncomment the following line:
RewriteBase /
Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]#pagespeed modifications
#RewriteCond %{HTTP:Accept-encoding} gzip
#RewriteCond %{REQUEST_FILENAME}.gz .f
#RewriteRule ^(.).css $1.css.gz [L,QSA]
#RewriteCond %{HTTP:Accept-encoding} gzip
#RewriteCond %{REQUEST_FILENAME}.gz .f
#RewriteRule ^(.).js $1.js.gz [L,QSA]Custom redirects
RewriteCond %{HTTP_HOST} ^term.otherdomain1.co.uk$ [OR]
RewriteCond %{HTTP_HOST} ^(www.)?legacydomain1.org.uk$ [OR]
RewriteCond %{HTTP_HOST} ^(www.)?legacydomain2.co.uk$ [OR]
RewriteCond %{HTTP_HOST} ^(www.)?legacydomain3.com$ [NC]
RewriteRule ^ http://www.myprimarydomain.co.uk [L,R=301]RewriteCond %{HTTP_HOST} ^rethink.otherdomain.co.uk$ [NC]
RewriteRule ^ http://www.myprimarydomain.co.uk/rethink [L,R=301]RewriteCond %{HTTP_HOST} ^(www.)?otherdomain2.org.uk$ [NC]
RewriteRule ^ http://www.myprimarydomain.co.uk/section/funding [L,R=301]<files "cron.php"="">Order deny,allow
Allow from 10.200.152.4
Allow from 10.200.152.5
Allow from 127.0.0.1Deny from all</files>
page speed optimisations
<ifmodule mod_expires.c="">ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"</ifmodule>
<ifmodule mod_headers.c=""><filesmatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$"="">Header set Cache-Control "max-age=2592000, public"</filesmatch>
<filesmatch "\.(css)$"="">Header set Cache-Control "max-age=604800, public"</filesmatch>
<filesmatch "\.(js)$"="">Header set Cache-Control "max-age=216000, private"</filesmatch>
<filesmatch "\.(xml|txt)$"="">Header set Cache-Control "max-age=216000, public, must-revalidate"</filesmatch>
<filesmatch "\.(html|htm|php)$"="">Header set Cache-Control "max-age=1, private, must-revalidate"</filesmatch></ifmodule>$Id: .htaccess,v 1.90.2.5 2010/02/02 07:25:22 dries Exp $
Hope that is of use.
Kind regards,
C
-
Hi there,
Do you have access to what the .htaccess file looks like at the moment, i.e. how have the 302s been set up?
Cheers,
Jane
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
-
Should we set up redirects for all deleted TAGS?
We recently found our site had 65,000 tags (yes 65K). In an effort to consolidate these we've started deleting them. MOZ is now reporting a heap of 404 errors for tag pages. These tag pages should not have links to them so not sure how come they're being crawled. Any suggestions from experience in this area would be useful.
Technical SEO | | wearehappymedia0 -
Missing 301 redirects
I just had a developer friend call me in a panic, because they had gone live with a new site and found out (the hard way) that they had missed some pages on their 301 redirects. So the pages are appearing in Google but serving 404s. Ouch! So their question was: other than running a report for 404 errors in something like Screaming Frog, is there a way to hunt down ONLY pages serving 404s, then export to CSV so they can be redirected? Anyone got any tricks up their sleeve?
Technical SEO | | muzzmoz0 -
301 Redirects
Hi, We have migrated to a new domain name and I wrote my redirects as follows: Redirect 301 / http://www.healthpointe.net Redirect 301 /urgent_care_locations.shtml http://www.healthpointe.net/healthpointe-locations/ Redirect 301 /locations.shtml http://www.healthpointe.net/healthpointe-locations/ Redirect 301 /career_client_relations_rep.shtml http://www.healthpointe.net/careers/ My issue is that when I include the first redirect, which is to the main page of the website that the other redirects stop working. Any idea what the problem could be?
Technical SEO | | healthpointeseo0 -
Sitelink Demotion Question
A non profit in our industry that we support pro bono--the awesome Efficiency First--is finding that individual member listings are sometimes showing up within their sitelinks. This obviously does not sit well with the members who do not show up. I know that you can "demote" specific URL's within webmaster tools, but I'm wondering if it's possible to demote an entire section. Their structure is www.efficiencyfirst.org/member/member#. Do we demote the entire member section? Or is there a more structural problem at play here? Thanks much. 2IZuPkD.png
Technical SEO | | PeterTroast0 -
301 redirect from Blogger
Hello, I have a client with a Wordpress network of blogs, each blog is owned by a different blogger. Many of them were migrated time ago from Blogger. I have seen that the way used to redirect them is a meta refresh, so no authority is being passed. I cannot find any reliable way of making a 301 from Blogger, There are some plugins, but I'm afraid of using them. Any of you have experience with this situation please? I have even thought about placing a global rel canonical before the meta refresh, but I think that here the problem is the meta refresh itself.... Thank you in advance
Technical SEO | | Juandbbam0 -
Canonical Question
Our site has thousands of items, however using the old "Widgets" analogy we are unsure on how to implement the canonical tag, and if we need to at all. At the moment our main product pages lists all different "widget" products on one page, however the user can visit other sub pages that filter out the different versions of the product. I.e. glass widgets (20 products)
Technical SEO | | Corpsemerch
glass blue widgets (15 products)
glass red widgets (5 products)
etc.... I.e. plastic widgets (70 products)
plastic blue widgets (50 products)
plastic red widgets (20 products)
etc.... As the sub pages are repeating products from the main widgets page we added the canonical tag on the sub pages to refer to the main widget page. The thinking is that Google wont hit us with a penalty for duplicate content. As such the subpages shouldnt rank very well but the main page should gather any link juice from these subpages? Typically once we added the canonical tag it was coming up to the penguin update, lost a 20%-30% of our traffic and its difficult not to think it was the canonical tag dropping our subpages from the serps. Im tempted to remove the tag and return to how the site used to be repeating products on subpages.. not in a seo way but to help visitors drill down to what they want quickly. Any comments would be welcome..0 -
Double 301 redirect
Hi together, due to some technical reasons I have redirect (301) an existing link two times. Example: www.mydomain.com/root/site.html > 301 > www.mydomain.com/site.html > 301 www.mydomain.com/site_new.html Is there anybody how has got some experience like doing a double redirect? What about link juice? Best regards Steffen
Technical SEO | | steffen_0 -
.htaccess and www - non www
Recently I have taken over a website and I made a pretty colossal mistake. The site was properly constructed via .htaccess to a www domain. Typically I roll without it and I made a bad assumption that the .htaccess was not previously set correctly because there were hundreds of fundamental mistakes. After a couple of days I noticed the mistake but some of our new (non www) have picked up some solid links etc. So now I feel that I am in a nightmare of creating redirects etc. So should I switch back to WWW or not? Does it matter at this point?
Technical SEO | | mikeusry0