The old site had a (302) redirect from / to /index.shtml.
The new site will be visible on / instead.
For SEO reasons we want a 301 redirect from /index.shtml to /.
However if I add that redirecting the htaccess file we get stuck in an infinite loop. So somewhere there still has to be a redirect from / to index.shtml, but where?
The old site was installed in the root directory /.
The new site is still in /dev/ (not my choice), however htaccess makes sure when someone goes to / they actually see the site in /dev/. The htaccess is saved in / and not /dev/.
Where could the old redirect from /index.shtml to / be?
My line of code in htaccess that creates a problem:
Redirect 301 /index.shtml http://www.example.com/
Could the error be caused by:
IfModule mod_rewrite.c (with brackets)
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
/IfModule (with brackets)
Your Redirect is causing the infinite loop .as it redirects /index.shtml to your document root which already points to /index.shtml .
To fix this or to set the **/index.shtml** as your root directory handler ,you can use one of the following methods :
DirectoryIndex
DirectoryIndex index.shtml
DirectoryIndex will internally forword your **/** home directory to **/index.shtml** .
Mod-rewrite :
RewriteEngine ^$ /index.shtml [L]
This will rewrite your home directory to **/index.shtml** .
if you want to redirect /index.shtml to / , you can use the following rule :
RewriteEngine on
RewriteCond %{THE_REQUEST} /index\.shtml\s
RewriteRule ^index.shtml$ / [L,R]
This will redirect /index.shtml to / without causing the infinite loop.
I know I'm coming late to the party, but the issue is the browser not the site. 301 and 302 redirects are both cached by recent browsers so you'll experience loops when you change them to point back to something that previously redirected.
You can test it with incognito mode and you'll see the redirect loop won't happen for you anymore. This is because incognito mode doesn't cache or observe the cache for redirects outside of its own session.
Unfortunately, there's no way to ensure that previous visitors don't get stuck in the loop which is why you should be very careful using 301 redirects. 302 redirects, as "temporary" redirects, will behave better with redirection loops, but the better solution would have been to use DirectoryIndex to load index.shtml as the default document instead of redirecting to it (which is what ultimately caused your problem).
Related
I developed a new WordPress website at www-newdomain-com
(Sorry, using dashes instead of dots in the domain names as i cant post more than 2 links here without a reputation score of 10?..)
The old website at www-olddomain-com was prematurely redirected via DNS (#A records, www records) to www-newdomain-com. I therefore don't have access to a hosting container to create an htaccess file on www-olddomain-com to 301 redirect all the old pages to their new locations. I also have a parked domain setup for www-olddomain-com under www-newdomain-com - it's not an ideal situation, but i'm stuck :-)
The url page names are also completely different on both domains.
WordPress also stores the site address www-newdomain-com in the database and basically hard codes it everywhere.
Wordpress htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Question:
How do I create 301 redirects in htaccess on newdomain in this above scenario?
If I use the following:
Redirect 301 /blog http://www.newdomain.com/articles
then it works initially, but as soon as I click any working link on www-newdomain-com thereafter, I receive a 500 internal server error.
If I use the following:
Redirect 301 /blog /articles
then it also works, but it displays the following in the address bar: olddomain-com/articles instead of www-newdomain-com/articles
I also have many of these: www-olddomain-com/blog/?cat=136
If I use:
Redirect 301 /blog/ /articles
then it loads the new domain 404 page and the address bar displays: http://olddomain-com/articles/?cat=136
I'm in the dark on this one and dont have any experience with htaccess other than the very basics. Any advice will be greatly appreciated, thanks!
First, you need to make sure you update the wordpress domain configuration to www-newdomain-com (go to /wp-admin/options-general.php to change it), otherwise it will rewrite every link to olddomain-com and mess up with your .htaccess rules.
This is why everything points back to olddomain-com for now.
I made a huge mistake. I set up a network without changing sitename to non-www, so now example.com (without www) is a non-existing page. How do I fix this? Changes in
settings
DNS
htaccess
?
I've tried htaccess redirect but wordpress sees the first request and still says www is missing.
We can't edit the Wordpress source code to redirect, as it will be broken on future updates. We can't forward all requests to the www-version of that request as that will break all subdomains.
I solved this with some edits to the root .htaccess file.
# This is probably how your file starts already
RewriteEngine On
RewriteBase /
# Then you add a condition: if the host starts with example.com
RewriteCond %{HTTP_HOST} ^example.com.*$
# And add a rule: redirect that url to the same url just with prepended with www
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Here the file continues with other stuff from WP
RewriteRule ^index\.php$ - [L]
I'm in a siutation where I need static pages to take over for much of a wordpress site I'm working with. I have created a /static directory in order to hold the static pages, but I also need to keep the exiting blog visible. I have the following code in my .htaccess file:
RewriteEngine On
RewriteRule ^blog index\.php [L]
RewriteRule ^20* index\.php [L]
RewriteRule ^$ static [L]
Going to mydomain.com/blog or mydomain.com/2014/01/blog-post both work, but if I try to go to mydomain.com the URL is being redirected to mydomain.com/static which is not what I am trying to accomplish.
Additionally, trying to visit any other page such as mydomain.com/about.php throws a 404 error which makes me think my rewrite is entirely wrong. Essentially I want all requests except for the blog page and blog posts to be rewritten to the files in /static
You need a trailing at the end of the directory or else mod_dir and DirectorySlash will redirect the browser to the URL with the trailing slash. So you're 3rd rule needs to be:
RewriteRule ^$ static/ [L]
Initially used a 301 to redirect www.example.com/ → www.example.com/wp
Unfortunately, I didn't read all the 'don't use 301 unless your 100% sure it's permanent' and now I need to revert back to the original domain.
At first, I tried to do a regular site url/wordpress url change in Setting/General in the admin dash. Saved over the old .htaccess on the root that had the original 301 redirect. Didn't work.
I moved everything to the root directory because I was getting a 'This webpage is a redirect loop' error page. Cleared cache on all browsers. Still getting the redirect loop error page.
Checked my url redirection here: http://www.digitalcoding.com/tools/url-redirect-check.html
I have two prompts, the first is going through fine, the second is a big fat X in red:
301 Moved Permanently: www.example.com/ → www.example.com301 Another Redirect Detected: www.example.com
.htaccess looks like this:
#Use PHP 5.4
AddType application/x-httpd-php54 .php
<IfModule mod_suphp.c>
suPHP_ConfigPath /opt/php54/lib/php.ini
</IfModule>
ErrorDocument 401 default
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any insight?
Redirect 301 / http://www.example.com/
You get an endless loop because there is nothing in that code to tell it not to redirect www.example.com to itself.
You are correct that you cannot use the Redirect directive, and this is the reason; It is unconditional, and will cause a loop in the scenario you describe.
In order to prevent the loop, you must find a way to tell the code not to redirect www.example.com to itself. This can be done by using mod_rewrite, and specifically, the RewriteCond directive in mod_rewrite, to test the requested hostname and act accordingly:
Options +FollowSymLinks -MultiViews
RewriteEngine on
#
# if requested hostname is non-blank
RewriteCond %{HTTP_HOST} .
# and if requested hostname is NOT "www.example.com"
RewriteCond %{HTTP_HOST} !^www\.example\.com
# redirect to same object in correct domain
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
The first directive, Options, may or may not be required on your server. If it is not required, it may in fact not be allowed. Comment it out of you have trouble.
The second directive, RewriteEngine, is required once (and only once) at the top of your mod_rewrite code.
The third directive, the first RewriteCond, is only required if you do not use a name-based virtual (shared) server. It prevents an infinite loop if the client does not send a "Host" header with its request. Since it is impossible to access a name-based virtual server without a "Host" header, this line is not required on a name-based virtual server. No harm will come from leaving it in, except that it takes a little time to process it.
Note that this code will also redirect "example.com" to "www.example.com", and so serves to canonicalize your main domain name as well, preventing ranking dilution from having duplicate content on two variations of the domain.
I've been searching online for over an hour trying to find out why my .htaccess file isn't working as expected, but all the docs and questions about .htaccess seem to say everything should be fine. i am using a wordpress site now and need to redirect some old links to *.html files to new permalinks (one by one as the naming convention has changed completely). so my .htaccess file looks like this:
# Redirects for old URLs
redirect 301 /contact_us http://rpcdev.thisisforge.com/contact/
redirect 301 /about_us http://rpcdev.thisisforge.com/about/
redirect 301 /clients http://rpcdev.thisisforge.com/work/
redirect 301 /clients/event.html http://rpcdev.thisisforge.com/work/event-retail-design/
redirect 301 /clients/identity.html http://rpcdev.thisisforge.com/work/identity-branding/
redirect 301 /clients/web.html http://rpcdev.thisisforge.com/work/web-design/
redirect 301 /clients/corp_lit.html http://rpcdev.thisisforge.com/work/brochures-publications/
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
The First three are working fine, it's the ones from specific .html pages that are not. I've tried putting the code both above and below the WOrdPress code, and I've tried switching the order of my 301s so the .html redirects are first, not last. but this doesnt help. Weirdly, sometimes the corp_lit.html redirect works ok, but the others don't. i can see no rhyme or reason to this!
Is my browser or OS (windows s7) caching the 301s from the .htaccess or something, back from when they were maybe incorrectly typed? i've tried emptying browser cache and flushing DNS in command prompt, but to no avail.
Pull
Any help much appreciated.
The Redirect directive links path nodes together, so your first /clients redirect is being applied instead of the following ones, try changing it to use RedirectMatch instead
RedirectMatch 301 ^/clients/?$ http://rpcdev.thisisforge.com/work/