.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
-
Redirecting an Entire Website?
Is it best to redirect an old website to a new website page by page to like pages or just the entire site all at once to the home page of the new site? I do have about 10 good pages on the site that are worth directing to corresponding pages on the new site. Just trying to figure out what is going to preserve the most link juice. Thanks for the help!
Technical SEO | | photoseo10 -
Technical URL SEO question
Hi All, We sell a product on our site which is displayed in cubic metres, from an SEO perspective is it ok to have /3mÂł in the URL or should I use 3m3. Thanks All
Technical SEO | | Redooo0 -
Duplicate content question
Hey Mozzers! I received a duplicate content notice from my Cycle7 Communications campaign today. I understand the concept of duplicate content, but none of the suggested fixes quite seems to fit. I have four pages with HubSpot forms embedded in them. (Only two of these pages have showed up so far in my campaign.) Each page contains a title (Content Marketing Consultation, Copywriting Consultation, etc), plus an embedded HubSpot form. The forms are all outwardly identical, but I use a separate form for each service that I offer. I’m not sure how to respond to this crawl issue: Using a 301 redirect doesn’t seem right, because each page/form combo is independent and serves a separate purpose. Using a rel=canonical link doesn’t seem right for the same reason that a 301 redirect doesn’t seem right. Using the Google Search Console URL Parameters tool is clearly contraindicated by Google’s documentation (I don’t have enough pages on my site). Is a meta robots noindex the best way to deal with duplicate content in this case? Thanks in advance for your help. AK
Technical SEO | | AndyKubrin0 -
Meta Data Question
Hi There, I am working on the umbraco CMS and we have a Menu page which sits under one page on the CMS. When accessing this page on the front end and navigating between the food menu / drinks menu, the url changes depending on which content you are on, however i have only one place to input a meta title and description meaning that it is seeing them as duplicate content as both the drinks menu url and food menu url are showing the same meta data. Hopefully this makes sense, does anyone have anything similair where a url change happens when content within the page changes.
Technical SEO | | AlexStanleyGK0 -
Do I need Redirects?
I've recently changed my old static website to a WordPress one. I'd like to know what do do (if anything) about my old links. For example a page on my old site was: www.iainmoran.com/corporate-magician.html - now I'm using WordPress, the url is:
Technical SEO | | iainmoran
www.iainmoran.com/corporate-magician/ My question is, do I need to set up redirects on these old pages (which no longer exist or will Google eventually re-crawl my site and update the links themselves? I'm using the Yoast SEO Plugin for WP and it creates a sitemap, which of course will have my new pages on. But don't want Google to penalise me for having broken links, etc. Many thanks, Iain.0 -
IP redirects
My website, on a .com domain, displays a different language/content depending on the IP of the user. For example, if someone is browsing my web from Spain, it will show the spanish content, and so on. Does anyone has an idea on how will Google index my pages? Their servers being located in the US, I assume the bot will only crawl and index the english content. How can I tell the bots to do the same for the other languages/content? Thanks!
Technical SEO | | Alemoto0 -
Domain tld question
Hi all, I have a question regarding the ranking of exact match tld which is co.uk Currently I have a .com domain with PR of 3 and the problem is that it have one word in front of my desired keyword, so it's not exact match. I have managed to buy an exact match but it's co.uk The questions are: Will a co.uk rank better for UK than .com domain I am reading at SEOMOZ that exact match domain value is getting lower, so is it worth to redirect my current .com domain to co.uk just to get rid of that one word and start all over again with exact match. Thanks
Technical SEO | | VasilTasev0 -
Meta tags question - imagetoolbar
We inherited some sites from another vendor & they have these tags in the head of all pages. Are they of any value at all? Thanks for the help! Wick Smith
Technical SEO | | wcksmith0