htaccess or php 301 redirect url - .htaccess

I do not know a lot htaccess and redirect url (301) with php as;
header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: http://www.exampledomain.com" );
Is there any difference or advantage between the two for google?Can I must use htaccess for redirect url?

You have to use both these headers to redirect something permanently. Both headers are needed. I echo this same header for my old blog url. And I get all the referrals, visitors, inlinks from google to the new domain.
It does not matter how you echo the headers. It matters those headers exist.
I know PHP well so I have used a PHP file that echos only these headers
HTTP/1.1 301 Moved Permanently
Location: http://shiplu.mokadd.im/
If you use 302 redirect Google will remember your current url and associate all your links to that old url.

Related

Redirect full URL to another full URL?

I want to 301 redirect from https://whatever-12345.de/something.html to https://whatever.de/something.html using a .htaccess file. I could not find a working example and this does not work:
redirect 301 https://whatever-12345.de/something.html https://whatever.de/something.html
Ideas?
First alternative, redirect a specific page called /sourcepage.html to another URL:
Redirect 301 /sourcepage.html http://Exampledomain.com/
Second alternative, redirect the whole domain to another URL:
Redirect 301 / http://www.Exampledomain.com/
And last, redirect one file to another file, locally, in the same domain:
Redirect 301 /old/path/oldpage.html http://www.currentdomain.com/new/path/newpage.html
PHP:
Now, by this method, you need FTP access to edit files in your server as well. We will create a PHP file named old.php. Here’s how this file will look like:
<?php
header("Location: http://www.mynewwebsite.com/blog/");
?>
This way, whenever we access this specific PHP file, the user will be redirected to our destination site.
We can also use a more complete PHP file, specifying that this is a 301 redirect (permanent). In this case, the PHP file would look like:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.mynewwebsite.com/blog/");
?>

301 redirect from one domain to another but only for specific pages

We are rebuilding a website for a client from ASP to WordPress. This website will have a different domain, url structure, and file extension. I am only just getting my head around htaccess 301 redirects, and I know enough that I can't do the following:
Redirect 301 http://www.site1.com/about_us.asp https://site2.com/about/
Redirect 301 http://www.site1.com/art-specs/ https://site2.com/specs/
Redirect 301 http://www.site1.com/page/product1/ https://site2.com/product1/
There are about 12 links in total that need to be redirected, and I want to make sure that it is done right the first time as a client's SEO rankings are on the line.
Is there a variation of the above format that I could use? Or a rewrite rule that needs to be done first? Any help (and explanations) would be greatly appreciated!
After looking more into it, I realised that the htaccess file shouldn't need anything other than relative access to the original domain.
i.e. You shouldn't need to declare: http://www.site1.com/about_us.asp since the server and domain should be configured in such a way that /about_us.asp means the same thing.
So the correct answer would be to:
[1] Configure the server (in my case cPanel) by having the original domain added as an addon domain (e.g http://www.site1.com/).
[2] In the htaccess file I would add each of the 301 redirects to the htaccess file:
Redirect 301 /about_us.asp https://site2.com/about/
Redirect 301 /art-specs/ https://site2.com/specs/
Redirect 301 /page/product1/ https://site2.com/product1/
...for each redirect
[3] And finally, adding the following to the bottom of the htaccess file will catch everything else and redirect them to the home page:
RedirectMatch 301 .* https://site2.com

Redirect entire site to other url with htaccess

I have a site which you can access with or without https rule. So, I need to make a redirect to another page. Example:
My website is: www.google.com so I can access by the moment as https://www.google.com and http://www.google.com but I need when you get into my website trough http or https way you must have to redirect to www.yahoo.com.
Besides I need the url redirection too to any subdomain or url which exists in http://www.google.com or https://www.google.com
How can I do this? I have no found alredy information about it in S.O. Thanks.
Very simple. You can use the following Redirect in your htaccess to redirect all requests from your site to the other domain
RedirectMatch 301 / http://yahoo.com/

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

301 redirect to new URL from htaccess

Needs a favour from your side, I have added following rule in htaccess files not sure why it is not executing can you check and let us know if any issue
Redirect 301 /product/rose-elliot%E2%80%99s-__060727.aspx http://www.website.co.uk/ahhgh.html
Redirect 301 /abc/%20/index.php/customer/account/login/ https://www.website.co.uk/customer/account/login/
URI's get decoded before being sent through the URL-file-mapping processing pipeline. So you need to unescape the %'s:
Redirect 301 "/product/abcd.aspx" http://www.website.co.uk/abcd.html
Redirect 301 "/abcd/ /index.php/customer/account/login/" https://www.website.co.uk/customer/account/login/
You'll need to make sure you're using a text editor that supports unicode.

Resources