.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
-
Avoid landing page redirects
Avoid landing page redirects for the following chain of redirected URLs. http://domainname.com/ https://domainname.com/ https://www.domainname.com/ Anyone know how to solve this issue the correct way?
Technical SEO | | Sammyh0 -
Redirect Chain Issue
I keep running into a redirect chain issue trying to get a non-https/non-www domain to forward directly to the https/www domain on an Apache server. For background, we are forcing https and forcing www, but it appears the non-https/non-www domain is first redirecting to https/non-www and then redirecting again to the desired final https/www version of the domain. (Hope I am making sense here) I am trying to find code to add to my .htaccess file that will perform the following... 301 Redirect
Technical SEO | | FitzSWC
http://example.com directly to https://www.example.com (without 1st redirecting to https://example.com)
http://www.example.com directly to https://www.example.com Any experts in this with any thoughts? Thanks,
Fitz0 -
301 redirect and search engines
How long until 301 redirects get recognized by search engines? I noticed my link on Google isn't forwarding over to my new domain even after the 301 redirect. If I go to the site directly, the 301 redirect works. Anyone know how long it takes for search engines to pick it up? Thanks!
Technical SEO | | timeintopixels0 -
301 redirect .htaccess
Hi guys I am working on some 301 redirects on an apache webserver and I'd like a bit of assistance in trying to get a specific type result: I want all addresses from domaina.com to be redirected to domainb.com in the same structure so domaina.com/folder/file will go to domainb.com/folder/file expect for 2 folders.
Technical SEO | | seobackbone
ie: DomainA.com --> DomainB.com
except domainA.com/folder1
and domainB.com/folder2 Can someone let me know how I can pull this off?0 -
301 redirect of a subdirectory
Hello! I am working on a website with the following structure: example.com/sub1/sub2/sub3. The page "example.com/sub1" does not exist (I know this is not the optimal architecture to have this be a nonexistent page). But someone might type that address, so I would like it to redirect it to example.com/sub1/sub2/sub3. I tried the following redirect: redirect 301 /sub1 http://example.com/sub1/sub2/sub3. But with this redirect in place, if I go to example.com/sub1, I get redirected to example.com/sub1/sub2/sub3/sub2/sub3 (the redirect just inserts extra subdirectories). If someone types "example.com/sub1" into a browser, I would "example.com/sub1/sub2/sub3" to come up. Is this possible? Thank you!
Technical SEO | | nyc-seo0 -
Where is the 301 redirect?
Hi, in the last week I take an issue for 301 permanent redirect for a subfolder in the main website! In that folder i have a index.php file for a google map fullscreen edition and the only link who connects the wordpress website with the subfolder is only a direct link! Is that an error of seomoz app or something else? Thanks 1.jpg
Technical SEO | | petrospan0 -
Wordpress question
I was curious when i run an OSE report on certain websites and their name.wordpress.com shows up with a PA of whatever and a DA of 100. But when I created my wordpress site and post on it, it only has a PA and DA of 1. is this because SEOmoz has not indexed it yet? It is a month old. http://shiftinsurance.wordpress.com/ Can anyone help pls?
Technical SEO | | greasy0 -
Pagination question
I have a website http://www.example.com  with pagination series starting with page1.html upto page10.html. With backlinks to some of the pages ( page1.html, page2.html----page7.html). If i include rel="next" and rel="prev" on page1.html to page10.html pages. Will value of those links will be transfered to http://www.example.com This is what i interpret from  http://bit.ly/mUOrn2 Am i right ?
Technical SEO | | seoug_20050