redirect using .htaccess not working - .htaccess

I'm trying to redirect using .htaccess from a subfolder to another domain using the following code:
Redirect 301 / https://newsite.com
Subfolder name is oldfolder
When I click http://website.com/oldfoler, I'm redirectd to https://newsite.com/oldfolder. When I click on http://website.com/oldfoler/about-us, I'm redirected to https://newsite.com/oldfolder/about-us
My .htaccess file is located in oldfolder
What am I doing wrong?

That is because that is the default behavior of Redirect.
Then any request beginning with URL-Path will return a redirect
request to the client at the location of the target URL. Additional
path information beyond the matched URL-Path will be appended to the
target URL.
https://httpd.apache.org/docs/current/mod/mod_alias.html#redirect
You need to use RedirectMatch or RewriteRule.
So if you want to redirect /oldfolder to new domain you can do this.
RedirectMatch 301 ^/oldfolder/? http://newsite.com/

Related

htaccess - redirect parent folder to file within parent folder

I'm attempting to redirect the user to a file within a folder if the user types the folder's address as a URL.
For example:
https://www.example.com/shop
should redirect to:
https://www.example.com/shop/en_GB/index.html
I've tried to do it using a htaccess file in the root with the following rule:
Redirect 301 /shop https://www.example.com/shop/en_GB/index.html
but this does not work - it adds the file URL over and over again in the address bar.
Can anyone help? Thanks.
Redirect directive matches any URI pattern that starts with the given string. Hence you're getting a redirect loop.
You should use RedirectMatch directive for this purpose that supports regex and allows you to match precise strings.
RedirectMatch 301 ^/shop/?$ /shop/en_GB/index.html
Make sure to use a new browser for your testing or clear browser cache completely.

Redirect Old URL to New URL open cart using htaccess

I want to redirect 301 old url to new url.
my old url is;
http://www.domainname.com/special
and new url is;
http://www.domainname.com/offers
I tried this code:
redirect 301 /http://www.domainname.com/special http://www.domainname.com/offers
But still now it's not redirecting & taking me to the old URL which does'nt exist.
Try this :
Redirect 301 /special /offers
Second argument of Redirect Directive is the URL Path, it doesn't start with Scheme and hostname.
There are various ways to do this and various redirects, I've listed them below:
301 (Permanent) Redirect: Point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the "example.com" domain:
This allows you to redirect your entire website to any other domain
Redirect 301 / http://example.com/
302 (Temporary) Redirect: Point an entire site to a different temporary URL. This is useful for SEO purposes when you have a temporary landing page and plan to switch back to your main landing page at a later date:
This allows you to redirect your entire website to any other domain
Redirect 302 / http://example.com/
Redirect index.html to a specific subfolder:
This allows you to redirect index.html to a specific subfolder
Redirect /index.html http://example.com/newdirectory/
Redirect an old file to a new file path:
Redirect old file path to new file path
Redirect /olddirectory/oldfile.html http://example.com/newdirectory/newfile.html
Redirect to a specific index page:
Provide Specific Index Page (Set the default handler)
DirectoryIndex index.html

url redirection in magento not working with index.php

I want to redirect url in magento. I am using "URL rewrite Management".
We want this path "/index.php?cPath=1" redirect to "baby-prams-strollers.html" this path.
I have entering data this type
Request Path * index.php?cPath=1
Target Path baby-prams-strollers.html
But it will be redirect on homepage. we want to redirect on baby-prams-strollers.html this path. How can we do this? Please advice me.
If we have entered this type of data
Request Path * ?cPath=1
Target Path baby-prams-strollers.html
Now it will be redirected on "baby-prams-strollers.html" this path but url is coming with index.php/baby-prams-strollers.html. Now we don't need index.php in URL. How can we remove index.php in this URL. We have already removed index.php in our all url. but when we redirection of this type url that time it will be added url in index.php.
Thanks in advance.
You need to add to your .htaccess file in your Magento root folder soomething like this:
RedirectMatch 301 /index.php?cPath=1(.*) /baby-prams-strollers.html$1

htaccess redirect to another domain - specific pages then remaining to go to homepage

I am in the process of redirecting an old site to another domain. Using htaccess I have listed around 40-50 specific pages to be re-directed to it's equivalent on the new domain i.e:
redirect 301 /delivery.php http://www.newdomain.com/delivery/
redirect 301 /contact.php http://www.newdomain.com/contact-us/
redirect 301 /about.php http://www.newdomain.com/about/
redirect 301 /stores/finder.php http://www.newdomain.com/branch-finder/
...
I then have probably around 600-700 other links where i don't need them to go to a specific page, just the new domains homepage. Is there a way I can have a 'and all other pages go to homepage' line or command to just go to http://www.newdomain.com? Otherwise I will have to manually type and enter each one
Is there a way I can have a 'and all other pages go to homepage' line
Yes sure you can have this rule as your last rule:
RedirectMatch 301 ^/.+ http://www.newdomain.com/

Redirect all website folders and files to the root of a new domain

I want to redirect all website including files that dont exist anymore to the root of the new domain.
Some examples:
Olddomain.com should go to newdomain.com
Olddomain.com/folder to newdomain.com
Oldomain.com/anyfolder/anyfile.pdf to newdomain.com
Olddomain.com/evenafile_that_doesnt_exists to newdomain.com
I was using
redirect 301 / newdomain.com
but this would require that the file exists in new domain with the exact path.
An extra challenge:
Redirect all old html files to new php in same path
Redirect all other files and directories with exact same path to newdomain.com where a page bot found error would appear in case path was incorrect.
Try:
RedirectMatch 301 ^ http://newdomain.com/
That will redirect everything to the same place.

Resources