How to remove 301 redirect from .htaccess? - apache

I am trying to fix this issue with my website where a Redirect 301 is applied. Here is my .htaccess:
RewriteEngine on
# Redirect "/" to Landing
RewriteRule ^$ http://greenengineering.com.au/landing/ [R=301,L]
# Additionally, redirect "/index.html" to Landing
RedirectMatch 301 ^/index\.html$ /landing
Can anyone guide me on how to remove this Redirection so that user can access the main domain http://greenengineering.com.au?

Simply remove the lines from your .htaccess. In case it does not work your browser may have cached the 301 redirect, as it is meant to be permanent. Try restarting your browser or use a another browser to check whether it worked.

While developing it's better to use temporary redirects (302) until you are sure of your rules.
The lines below will permanently redirect
http://greenengineering.com.au/ --> http://greenengineering.com.au/landing/
# Redirect "/" to /landing/
RewriteRule ^$ /landing/ [R=301,L]
The lines below will also permanently redirect
http://greenengineering.com.au/index.html --> http://greenengineering.com.au/landing/
# Redirect "/index.html" to /landing/
RewriteRule ^index\.html /landing/ [L=301,L]
Remove the rules that you no longer wish to use. If you find that the 301 redirect is still happening, then please see How can I make Chrome stop caching redirects? and How long do browsers cache HTTP 301s?

Related

Alternative for bulk Redirect 301 in htaccess

I have some link redirects in htaccess in which every link should be added with /en after .com i.e.,
mydomain.com, mydomain.com/abc.html
to
mydomain.com/en, mydomain.com/en/abc.html
After some research i found that redirect 301 does it. But I think this is not perfect and permanent solution. In future if I add another URL, again I have to add it to htaccess. So can any one help me out in getting the perfect and permanent solution for this.
I have done this in my htaccess
Redirect 301 /about.html /en/about.html
Redirect 301 /contact-us.html /en/contact-us.html
Redirect 301 /index.html /en/index.html
Redirect 301 /locations.html /en/locations.html
You can use this single redirect rule in your site root .htaccess:
RewriteEngine On
RewriteRule ^(?!en/)(.+\.html)$ /en/$1 [L,NC,NE,R=301]
(?!en/) is negative lookahead to assert that URI is not already starting with /en/.

htaccess 301 redirect not redirecting

tried several ways to make redirect, but not successfull
Redirect 301 /ru/pages/portfolio/ /ru/pages/portfolio/3/ [END,R=301]
or
Redirect 301 http://myssite/en/pages/portfolio http://myssite/en/pages/portfolio/3
and many others from internet, but all of them not working.
Need to redirect pages/portfolio to pages/portfolio/3 (for all languages - en, ru)
This is content of file
<IfModule mod_rewrite.c>
# Turn Off mod_dir Redirect For Existing Directories
DirectorySlash Off
# Rewrite For Public Folder
RewriteEngine on
Redirect 301 /ru/pages/portfolio/ /ru/pages/portfolio/3/ [END,R=301]
RewriteCond $1 !^(pma)
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Since you are already using mod_rewrite (for an internal rewrite) you should also use mod_rewrite for this redirect, rather than using a mod_alias Redirect. Different modules execute at different times during the request, despite the apparent order of the directives in the config file.
However, your example is unclear. The first example includes a trailing slash; the second does not? Is there a trailing slash or not?
Try something like the following instead after the RewriteEngine directive:
RewriteRule ^(en|ru)/pages/portfolio$ /$1/pages/portfolio/3 [R,L]
This excludes the trailing slash. And assumes "all languages" are just en and ru. This is also a temporary (302) redirect. Change to a permanent (301) redirect (if that is the intention) only when you are sure it's working OK, since 301s are cached by the browser. You will need to clear your browser cache before testing.
Redirect 301 /ru/pages/portfolio/ /ru/pages/portfolio/3/ [END,R=301]
:
Redirect 301 http://myssite/en/pages/portfolio http://myssite/en/pages/portfolio/3
Aside: Neither of these would have worked anyway. End flags like [END,R=301] are a mod_rewrite syntax, and do not relate to mod_alias (Redirect). And the URL-path matched by the Redirect directive should be a root-relative path beginning with a slash, not an absolute URL. See the Apache docs... https://httpd.apache.org/docs/current/mod/mod_alias.html#redirect

Apache Conditional RedirectMatch

I have moved a website from /blog/ to the web root. I created a RedirectMatch 301 for my URLs which I believe is correct:
RewriteEngine On
RewriteBase /
RedirectMatch 301 ^/blog/(.*)$ /$1
This works correctly. Now, domain.tld/blog/foo/ redirects to domain.tld/foo/
However, there is one issue. There is a page on the website with the slug: /blog/
Now you can't access the page since domain.tld/blog/ redirects to domain.tld/
So what I would like to accomplish is not to redirect /blog/, but to redirect /blog/everything/else/
domain.tld/blog/ no redirection
domain.tld/blog/foo/ redirects to domain.tld/foo/
domain.tld/blog/foo/bar/ redirects to domain.tld/foo/bar/
Etc.
Many thanks for your help!
Can you try this? I think it needs a little change:
RewriteEngine On
RewriteBase /
RedirectMatch 301 ^/blog/(.+)$ /$1
Remember to clear cache + history on browsers before testing, browsers remember 301 redirect rules.
Hope that helps.

.htaccess redirect folder to its subdomain causes redirect loop

I have a subdomain sub.domain.com
And the same contents are available on domain.com/sub
But now I want to redirect domain.com/sub to sub.domain.com
If I do that with
Redirect 301 /sub http://sub.domain.com
it causes a redirect loop.
How can this be solved technically? Users should not be able to access the subdomain content under domain.com/sub but should be redirected.
Better to use mod_rewrite rules here with conditions to restrict the rule only for domain.com requests:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?domain\.com$ [NC]
RewriteRule ^sub(/.*)?$ http://sub.domain.com/$1 [L,NC,R=302]
Make sure to test this after clearing browser cache.

Apache 301 redirect only for domains, not pages

I have a 301 redirect to set up for my domain (http://old-site.com and http://www.old-site.com).
I would like to redirect only if nothing appears after the domain in URL.
http://old-site.com redirect to http://www.new-site.com
http://www.old-site.com redirect to http://www.new-site.com
http://old-site.com/article/article-1.php DO NOT redirect
I have tried this but it always redirect, even if I directly call an article:
RewriteCond %{HTTP_HOST} ^(www\.)?old-site\.com
RewriteRule ^(.*)$ http://www.new-site.com/ [R=301]
It should be easy to set up, but I am a real newbe in this.
Thanks for your help.
Of course it redirects everything, because you matched “everything” with (.*).
Try matching for “nothing” instead, with just ^$.