HTACCESS redirection - apache

I changed the hierarchy of my site. there we 2 pages as following:
http://www.example.com/cms/products-search.php
Which moved to : /new/pro-search.php
And
http://www.example.com/cms/data-products-details.php?pro=1111
Which moved to /new/products-details.php?pro=1111
How can i handle this in htaccess and not affect SEO ?

You should redirect to your new page location using
301 "Moved Permanently" redirect
Which has to be setup pro grammatically in your HTACCESS file, simple example:
Redirect 301 /something https://www.mynewapp.com/something/a?someextra
The 301 "Perma Redirect" tell Search Engine that you page has moved for good at new location and any Page Rank should be transferred to new URL.

Related

How to set rule for 303 redirect?

I have internal links like: http://example.com/payment/
If to enter this link instead http://example.com/payment I get an error 303.
How to configure .htaccess for redirect?
Add this redirect into your .htaccess file.
This allows you to redirect your entire website to any other domain
Redirect 303 / http://example.com/payment/
Redirecting a URL: Using Redirect in an .htaccess file enables you to redirect users from an old page to a new page without having to
keep the old page. For example, if you use index.html as your index
file and then later rename index.html to home.html, you could set up a
redirect to send users from index.html to home.html.
For example:
Redirect /path/to/old/file/old.html http://www.example.com/new/file/new.html
You can find more detailed examples here.

.htaccess rules to redirect certain pages and the catch all others

I'm redirecting a site from an old platform to another. It's got 300-400 pages and all the pages have different names.
It's learn.example.com (old platform) to courses.example.com (new platform)
So I've put in some 301s at the beginning of the .htaccess file of the most important pages, for example:
Redirect 301 /courses-overview/ http://courses.example.com/courses
But at the end I need a catch-all to redirect any other page not previously specified as a 301 like learn.example.com/whatever to courses.example.com to catch any of the other 300-400 pages that don't exist in the .htaccess file now.
Is that possible?
You can Redirectother pages via the following Redirect :
RedirectMatch ^/.*$ http://example.com/
Put this bellow your existing Redirects otherwise Apache will redirect your whole site.

301 Redirect A URL Pattern Using .htaccess

I want to redirect my URLs to a new pattern. For this purpose, I used 301 redirect for every single URL but that are taking a huge time and my .htaccess file is going large and large as I have thousands of URLs.
So now Someone said to me to use .htaccess to use 301 redirect or rewrite engine option. Now I am new to .htaccess to use Pattern Redirect. First of all clear me out that is this possible to use 301 redirect in patterns? If yes then Can I do pattern 301 redirect in the below URLs? I want to redirect the below pattern so can you help me?
/search/label/XXXXXXXXXX to /category/XXXXXXXXXX
/year/month/XXXXXXXXXX.html/?m=0 to /year/month/XXXXXXXXXX.html
/year/month/XXXXXXXXXX.html/?m=1 to /year/month/XXXXXXXXXX.html
/search to /
/feed to /
XXXXXXXXXX means some text/no that are dynamic and changeable. year and month means only no that are also dynamic and changeable. / means site homepage. Rest are fixed text.
Please keep in mind that sometime there are many variables in every URL so we also want to avoid that that always start from ?variable=value&variable=value in the end of every URL.
After asking here, I keep trying myself too so I am able to do it and working on my side. I added below codes in my .htaccess file and after that I am able to redirect all upper URLs without any 404 error.
Redirect 301 /search/label http://www.example.com/category
Redirect 301 /search http://www.example.com
Redirect 301 /feed http://www.example.com
For 2,3 URL pattern, I did nothing because after checking, its not showing any 404 error as they are only variable in front of URL so no need to edit that.

Redirect all traffic from one folder to another

I have a blog hosted at say domain.com/site but have built a new website. I want to redirect all traffic from domain.com/site/anything to domain.com/home/ so that any traffic going to any page or file on the old site gets redirected to the new homepage.
I am unsure what code to place in the .htaccess file and also where on the server to place it
Simply:
Redirect 301 {old path} http://domain.com/{new path}
you can place that at the root of your website, with the old path and Apache will redirect to the new site.
In your case:
Redirect 301 /site/anything http://domain.com/home

Error is .htaccess - Redirects not working and its very strange

My site has just recently launched a bunch of new product pages, replacing the old ones.
Here is an example of a redirect I want. One going from the old page...redirecting to the new page. I checked Google webmaster and said that there was a not found error for the second link.
Redirect 301 /it-infrastructure.html http://www.example.com/managed-enterprise-services.html
Redirect 301 /it-infrastructure http://www.example.com/managed-enterprise-services.html
So the .html one is redirecting fine...but the one without the .html extension is not. BUT...what's strange is that I have a bunch of redirects from the past that don't use the html ext and work fine, such as:
Redirect 301 /broadsoft-web-portal http://www.example.com/broadsoft-web-portal.html
and
Redirect 301 /business-voip http://www.example.com/business-voip.html
Anyone have any idea why this isn't working?
Add to your .htaccess this line
Options -MultiViews