.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
-
Questions about the DA,PA of website
I am counting on some more ads on the site https://gogoanime.city/, is it a problem if I add some ads about sex, porn ..., to make a little more money. So does it affect the PA DA score. Thank you!
Technical SEO | | gogoanimetp0 -
Redirect indexed lightbox URLs?
Hello all, So I'm doing some technical SEO work on a client website and wanted to crowdsource some thoughts and suggestions. Without giving away the website name, here is the situation: The website has a dedicated /resources/ page. The bulk of the Resources are industry definitions, all encapsulated in colored boxes. When you click on the box, the definition opens in a lightbox with its own unique URL (Ex: /resources/?resource=augmented-reality). The information for these colored lightbox definitions is pulled from a normal resources page (Ex:Â /resources/augmented-reality/). Both of these URLs are indexed, leading to a lot of duplicate indexed content. How would you approach this? **Things to Consider:Â ** -Website is built on Wordpress with a custom theme.
Technical SEO | | Alces
-I have no idea how to even find settings for the lightbox (will be asking the client today).
-Right now my thought is to simply disallow the lightbox URL in robots.txt and hope Google will stop crawling and eventually drop from the index.
-I've considered adding the main resource page canonical to the lightbox URL, but it appears to be dynamically created and thus there is no place to access (outside of the FTP, I imagine?). I'm most rusty with stuff like this, so figured I'd appeal to the masses for some assistance. Thanks! -Brad0 -
RewriteQueryString and .htaccess usage
I'm trying to redirect a whole load of pages which use a query string to a different directory for example. Original URL: example.com/news/post.php?s=2011-01-28-some-text New URL:Â example.com/blog/post.php?s=2011-01-28-some-text My understanding is that because the url uses query strings I need to use a rewrite rather than the usual redirect 301 etc. I've come up with this but it is not doing the job. Any ideas what I'm doing wrong? RewriteEngine On
Technical SEO | | RodneyRiley
RewriteCond %{QUERY_STRING} s=
RewriteRule ^/news /blog [L,R=301]0 -
Javascript redirects -- what are the SEO pitfalls?
Q: Is it dangerous (SEO fallout) to use javascript redirects? Tech team built a browser side tool for me to easily redirect old/broken links. This is essentially a glorified 400 page -- pops a quick message that the page requested no longer exists and that we're automatically sending you to a page that has the content you are looking. Tech team does not have the bandwidth to handle this via apache and this tool is what they came up with for me to deliver a better customer experience. Back story: very large site and I'm dealing with thousands of pages that could/should/need to be redirected. My issue is incredibly similar to what Rand mentioned way back in a post from 2009: Are 404 Pages Always Bad for SEO? We've also decided to let these pages 404 and monitor for anything that needs an apache redirect. Tool mentioned above was tech's idea to give me "the power" to manage redirects. What do you think?
Technical SEO | | FR1230 -
301 Redirect with index.asp
I am very new to all of this so forgive the newbie questions I will get better.  Ok so after starting a campaign I see that I have many issues including where some pages are being deemed as duplicate content. 1. The report says the http://lucid8.com has duplicate content on 2 other pages 2. When I look at them it shows that http://lucid8.com/index.asp and http://www.lucid8.com are duplicates. 3. Really these are the exactly the same page because the default page that is opened for www.lucid8.com http://www.lucid8.com etc always opens the index.asp page. 4. Now I read that I should do permanent redirects and how to do this via IIS and I tried to do a redirect from index.asp to www.lucid8.com but that does not work because www.lucid8.com is pointing to index.asp and so we end up in a circle. So the question is how do I get rid of these duplicate page references without causing problems. Thanks
Technical SEO | | TroyW0 -
Wordpress Categories and Over-Optimization Question
I would like to switch my sidebar from listing Category Name with posts listed below each- to a concise custom menu. This custom menu would list the top three products I am promoting first, and then go on to list the categories on my site. Currently it looks like this (but with 6 categories, with between 7-10 items in each - this is on EVERY page) Widgets
Technical SEO | | PrivatePartners
-Green Widget
-Blue Widget Gidwets
-Big Gidwet
-Small Gidwet I rank well in google right now, but I am concerned that changing my sidebar will result in a penalty.  Maybe for over-optimizing my top three products I promote, or possibly for trying to control the flow of link juice. Can anyone chime in here who has adjusted their site structure within wordpress, and tell me what you found worked best? ** Before anyone asks**, this structure does work much better for the user.  My sidebar now is massive, and is confusing even to me.0 -
Htaccess rewrites
We’re using wordpress, and we have the following in the .htaccess: BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] END WordPress We have a URL like http://subdomain.example.com/select-a-card/?q=fuel, and I want to rewrite it so that it becomes http://subdomain.example.com/fuel-card/ What do I need to add to the htaccess to do this?? Thanks,
Technical SEO | | AndrewAkesson0 -
Is a 302 redirect the correct redirect from a root URL to a detail page?
Hi guys The widely followed SEO best practice is that 301 redirects should be used instead of 302 redirects when it is a permanent redirect that is required. Matt Cutts said last year that 302 redirects should "only" be used for temporary redirects. http://www.seomoz.org/blog/whiteboard-interview-googles-matt-cutts-on-redirects-trust-more For a site that I am looking at the SEO Moz Crawll Diagnostics tool lists as an issue that the URL /Â redirects to www.abc.com/Pages/default.aspx with a 302 redirect. On further searching I found that on a Google Support forum (http://www.google.com/support/forum/p/Webmasters/thread?tid=276539078ba67f48&hl=en) that a Google Employee had said "For what it's worth, a 302 redirect is the correct redirect from a root URL to a detail page (such as from "/" to "/sites/bursa/"). This is one of the few situations where a 302 redirect is preferred over a 301 redirect." Can anyone confirm if it is the case that "a 302 redirect is the correct redirect from a root URL to a detail page"? And if so why as I haven't found an explanation. If it is the correct best practice then should redirects of this nature be removed from displaying as issues in the SEO Moz Crawll Diagnostics tool Thanks for your help
Technical SEO | | CPU0