Need to one old url to new URL - .htaccess

I have convert old website to new website with URL Rewriting and It's working properly but as the seo manager, he asked to redirect 5 old urls to news urls because they are already on first pages in google search engines. He don't want any excuse and he want atleaset redirect 5 old url to new news. Please let me know how to redirect these pages to new urls.
OLD URL: www.example.com/ViewCategory.php?CId=1211
New URL: www.example.com/Carrom-Boards.html
Hope someone help me to fixed this.
Thanks & Best Regards

Well, sounds pretty straight forward:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^CId=1211$
RewriteRule ^/?ViewCategory\.php$ /Carrom-Boards.html [QSD,R=301,L]
It is a good idea to start with a R=302 temporary redireciton and only change that to a R=301 permanent redirection once everything works as desired. That prevents nasty caching issues for users.

Related

Update Apache rewrite rule in .htacess that will still allow for previous URLs to work

I'm working on updating an .htaccess file to update some URLs for an existing website.
Right now, the URLs look like:
nickwebsite.com/nicks-widgets/product-type
I'm trying to reduce the redundancy, to have the URLs look like:
nickwebsite.com/widgets/product-type
The RewriteRules in place now look like this:
RewriteRule ^nicks-widgets/product-type(.*)$ collection.php?category_id=64&%{QUERY_STRING} [NC]
I need to update these URLs to use the new URL, while still keeping the old URLS functional
I tried adding a Rewrite rule like so:
RewriteRule ^widgets/product-type(.*)$ collection.php?category_id=64&%{QUERY_STRING} [NC]
And also a Redirect like this, so that visitors who have the old URL saved will be redirected to the new URL:
Redirect 301 /nicks-widgets /widgets
But neither really work. Instead I'm seeing my URL combined when trying to access the new url, so I will get:nickwebsite.com/widgetsproduct-type?category_id=64 displayed in my browser. I'm really lost on what I am missing.. can anyone point me in the right direction?

How to redirect entire domain to new domain except homepage via htaccess

So I have found some questions that are close to what I need, but I haven't found exactly what I'm looking for.
While I've worked with htaccess files in the past, it's pretty much been just copying and pasting code that is proven to work, or just doing simple 301 redirects. To be honest, I get pretty confused when looking at htaccess rewrite rules, so unfortunately are not going to be able to do from scratch. So I'm really hoping there is someone kind enough to provide a code example just using placeholder domain names.
Here is my situation. I'm doing work for a company who has split up into different divisions (4). So they want to take the site on their current domain, move it to a different domain. Then put up a simple html splash page on the old domain that provides links to the 4 different sites they will have (one of those being what was the old site on a new domain).
So I need to redirect everything from olddomain.com to newdomain.com with the exception of the homepage. Not sure if this matters, but site that was on the old domain was a WordPress site so technically is index.php. But the new site/splash page is named index.html.
Thanks in advance!
So I need to redirect everything from olddomain.com to newdomain.com with the exception of the homepage.
You can use this rule in the site root .htaccess of olddomain.com:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !/(css|js|images)/ [NC]
RewriteRule . http://newdomain.com%{REQUEST_URI} [L,NE,R=301]
RewriteRule . will match everything except the home page just make sure this rule is the first rule in your .htaccess.

Url duplication with Prestashop SEO

I have an e-commerce developed with the CMS Prestashop.
Yesterday i have seen in my Webmaster Tools that i had some duplicated URL, like this:
www.mysite.com/manufacturers
www.mysite.com/it/manufacturers.
Where 'it' is the suffix of the default and only language for the website.
I've already activate the friendly URL in the back-office and also I've a .htaccess file generated automatically by the generator in the back-office.
What should I do to fix this issue?
PS: Also I think that I've already taken a penalization from googlebot.
First of all let me clarify the Title from the SEO point of view. The problem is from Prestashop side not from SEO side. It is just affecting your SEO.
Now on the problem, Prestashop is notorious for URL problems. I would not recommend you the .htaccess hack solution because every time you regenerate your .htaccess from you backend, you have to manually insert that hack again in it to keep the problem down. And suppose this url problem arises again after sometime for some other url than you have to do it again. It can turn into a nightmare.
So here are some of my personal recommendations...
If this site is critical(which I am assuming), buy a Prestashop url rewriting module from a trusted provider. You will also get a technical support in case this problem arises again in future.
If you can't buy than I would suggest you to ask this question on Prestashop forums, as this is Prestashop specific, to permanently solve this problem. You will most likely to get more instant answers as you will find more people working on Prestashop there than here.
Somewhere either in the htaccess file in your document root, or in the vhost/server config for mysite.com, you'll need to 301 redirect. Now you just need to choose which one you want to keep, the one with /it/ in front or the one without? Let's say you want to point everything to the one without, you'll use one of these:
Using mod_alias:
Redirect 301 /it/manufacturers /manufacturers
Using mod_rewrite:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mysite.com$ [NC]
RewriteRule ^/?it/manufacturers(.*)$ /manufacturers$1 [L,R=301]

Does mod_rewrite only translate external requests to internal files and not vice versa?

I think this is a very stupid question so I apologise, as i think i may completely misunderstand mod_rewrite.
Say you have a URL
www.domain.com/products/item.php?id=1234
mod_rewrite can rewrite that to a friendly URL
wwww.domain.com/products/item/1234
(for example)
So, if i type in wwww.domain.com/products/item/1234 this will be rewritten to www.domain.com/products/item.php?id=1234 and that page is served. Fine.
But what if you type in www.domain.com/products/item.php?id=1234 - that page will be served but not rewritten to the friendly URL.
So my question is can you rewrite internal file names automatically? For example, all URLs on my site are currently in the www.domain.com/products/item.php?id=1234 format. When a user clicks this link can this be rewritten to the friendly URL? Or should you always hard code in the friendly URL?
Im sorry if that made little sense! Im getting confused because i want to rewrite non-friendly to friendly URL, but then serve the non friendly URL - so wont that cause an infinite redirect loop?
Mod_rewrite can't really internally rewrite URLs across domains, though it could proxy them (using P option in RewriteRule). Assuming that the domain is the same, you could do something to redirect the client's browser to a friendly URL if the old one is used while internally rewriting the friendly URL back to the old one, but they have to be both the same domain. You do this by looking at the actual request (%{THE_REQUEST}) variable instead of looking at the URI, which changes as they get rewritten internally.
This redirects the browser when the old URLs are used to the friendly URLs
RewriteCond %{THE_REQUEST} ^([A-Z]{3,9})\ /products/item\.php
RewriteCond %{QUERY_STRING} id=([0-9]+)
RewriteRule ^products/item\.php$ /products/item/%1? [R=301,L]
This rewrites internally when a friendly URL is used:
RewriteCond %{THE_REQUEST} ^([A-Z]{3,9})\ /products/item/[0-9]+
RewriteRule ^products/item/([0-9]+) /products/item.php?id=$1 [QSA,L]
Mod_rewrite does not automatically rewrite the "none friendly" urls to the friendly urls. You have to add some rules yourself to do this.
Also Mod_rewrite does not modify the links inside your html, css, or whatever you use. You need to change those yourself.
If a user uses the friendly url, it will never know that it is rewritten. Mod_rewrite is tranparent from the user's point of view. You can add a [R] flag to your rules which makes apache send a redirect to the client. This way the client does see the rewritten url.
Redirecting the unfriendly to the fiendly url, should only be done to help search engines (and to prevent link-rot, but that's more rare). This can be done without a redirect loop, unlike Sergey says.
Try looking around here on SO to find a script that does the redirect from the unfriendly to the fiendly url. Let me know if you can't find it, and I'll help.

How does google react on a redirect to a redirect

I am migrating a website to a drupal CMS.
I would like to know how google responds on a redirect from a redirect.
I'll try to explain what i'm trying to accomplish:
The old situation: www.old-site.com/page?pid=123
The new situation: www.new-site.com/page/pagetitle
I want to create a 301 redirect in my .htaccess file as i have done for alot of other pages.
But in this particular situation the old page id (pid) is not known in the new website.
My plan is to create the following rewrite rules:
RewriteCond %{QUERY_STRING} ^pid=(.*)$
RewriteRule ^page.aspx$ page-redirect/%1? [R=301,L,NC]
Right now i have the correct page id. What i then want to do is create a little script that rewrites the url from page-redirect/123 to page-redirect/newtitle as i do know the title that comes with the id
Then i want to have the following rule handle the new title:
RewriteRule ^page-redirect/(.*)$ page/%1? [R=301,L,NC]
So basicly the bottomline question is: How does this affect the google index? Our client wants to maintain his (good) organic results in google.
Instead of Redirecting from page.aspx to page-redirect, why not Rewrite to page-redirect. That way page-redirect can figure out the final url page-redirect/newtitle and issue a single 301 redirect for it i.e.
RewriteCond %{QUERY_STRING} ^pid=(.*)$
#just do a server side rewrite instead of a redirect
RewriteRule ^page.aspx$ page-redirect/%1? [L,NC]
The redirect logic will exist within your page-redirect code.
If you still choose to do 2 301 redirects, it is not ideal, but Google should transfer the page-rank of the old urls to the new ones.
Note that either way, when you do move content via a 301 (1 or 2), you should expect a temporary dip in your page rank as your old pages drop off the index and the new ones are added.

Resources