Redirect permanent doesn't works - apache

I have just updated my site from an old asp platform to a new wordpress one. The seo company that is working with Us has inserted a lot of redirects in my htaccess. like this
Redirect permanent /viewdoc.asp?co_id=2664 https://www.anekitalia.com/cargo/
Redirect permanent /blog/evidenza-2/ https://www.anekitalia.com/blog/
Problem is that all the redirects of asp links are giving me always 404 page, the other links are working, so this is not related to my vps setup I think, maybe the links like /viewdoc.asp?co_id=2664 needs a different kind of redirect? hope someone can point me to a direction cause this will impact all my SEO activities.
many thanks

You can not use Redirect directive to redirect URL querystring . You need to use RewriteRule .
RewriteEngine on
RewriteCond %{QUERY_STRING} ^co_id=2664$
RewriteRule ^viewdoc\.asp$ https://www.anekitalia.com/cargo/? [L,R=301]

Related

Apache redirect if no parameters

I tried searching for this solution and apologize ahead of time if it was out there and I missed it.
I am working on setting up 301 redirects on an apache server to point old pages on a CMS to new pages. During the transition, we need to operate pages on both systems. They have a page that:
if has no GET parameters tacked on the end, should redirect to the new CMS
if it has GET parameters, it should NOT be redirected and should continue working with the old CMS
I have seen many mod_rewrite rules to do the opposite of what I am looking for, but not one that will only activate if there are no GET parameters. I have tried the following, but it did not work:
RewriteCond %{REQUEST_URI} ^/page.php$<br />
RewriteCond %{QUERY_STRING} ^<br />
RewriteRule ^.*$ http://new.domain.com [L,R=301]
If someone goes to old.domain.com/page.php they should be redirected to new.domain.com. If someone goes to old.domain.com/page.php?var=1&var=2, they should remain on this domain and not be redirected.
Thanks, in advance, for any help you could provide,
Dave

htaccess permanent redirect and remove string from url

How can I go about getting visitors who enter the site via a mobile url get redirected to the non mobile url on this example;
user visits http://website.com/*mobile/*the-page.html
redirect them to http://website.com/the-page.html
Doing a google search, I was able to come up with the follow htaccess line:
RewriteRule ^/?mobile/(.*)$ /$1 [L,R=301]
though it correctly redirects to the right page, it uses the filename of the dynamic page to do so, example:
http://website.com/index.php?id=the-page
how can I get it to just take out mobile/ from the url?
okay, slow moment... I needed to deleted the original rewrite rules for the mobile site.
after that, it was simple as adding
RewriteRule ^mobile/(.*)$ /$1 [L,R=301]
to htaccess.

Rewrite URL SEO

My site has a url like this
http://www.mydomain.com/index.php?page=doctors&docid=99
Using SEO rewrite
RewriteRule ^doctors/([0-9]+)/(.*).html$ index.php?page=doctors&docid=$1 [L]
I get
www.mydomain.com/doctors/13/Dr.-John-Smith.html
But I want a more friendly url like this
www.mydomain.com/Dr.-John-Smith.html
How can I achive this url.
REWRITING QUERY STRINGS
If you are hired to recreate an existing website from scratch, you might use URL rewriting to redirect the 20 most popular URLs on the old website to the locations on the new website. This could involve redirecting things like prod.php?id=20 to products/great-product/2342, which itself gets redirected to the actual product page.
Apache’s RewriteRule applies only to the path in the URL, not to parameters like id=20. To do this type of rewriting, you will need to refer to the Apache environment variable %{QUERY_STRING}. This can be accomplished like so:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=20$
RewriteRule ^prod.php$ ^products/great-product/2342$ [L,R=301]
RewriteRule ^products/(.*)/([0-9]+)$ ^productview.php?id=$1 [L]
In this example, the first RewriteRule triggers a permanent redirect from the old website’s URL to the new website’s URL. The second rule rewrites the new URL to the actual PHP page that displays the product.
I hope this helps, find out a lot more about rewrites here:
http://coding.smashingmagazine.com/2011/11/02/introduction-to-url-rewriting/
It's laid out in a pretty straight forward fashion. Hope that helps, please let me know if you have any other questions. Thank you.

How can I redirect links to an old home.asp file to a new index.php?

I am working on a website that has a lot of old, incoming links on external sites. These links point to http://domain.com/home.asp .
However, the current site is built in WordPress, with http://domain.com/ as the URL with index.php being in the root.
Currently, any links pointing to the home.asp are redirecting to a 404 Not Found. What is the best way to redirect those links to the new index.php? Is .htaccess my best bet?
Thank you for reading.
In .htaccess:
RewriteEngine On
RewriteRule ^/home.asp / [L,R=301]
should do the trick
L means stop rewriting after this line
R=301 means to send an MOVED PERMANENTLY respons to the client

Domain Redirects SEO relative to the root folder

I got two related problems in the site root.
First, both "domain.com" and "www.domain.com" works the same way. Is that a problem for SEO purposes? Some guy told to use a redirect. Should I do that? What redirect should I use?
Second, my visitors that visit the site over the "/" url get geolocated and redirect to a specfic page, it means, if the visitor access "www.domain.com" from the city a, he gets a redirect to "www.domain.com/a/", if the visitor came from city b, he gets a redirect to "www.domain.com/b/", etc... How should I work over that?
PS: Feel free to rename the question, I dont know how to name it properly.
Thx
First point answer:
Yes, you should redirect it. Otherwise you can run into the duplicated content issue. You can redirect using .htaccess and the code will be this:
RewriteEngine on
RewriteCond %{http_host} ^site\.com [nc]
RewriteRule ^(.*)$ http://www.site.com/$1 [R=301,nc,L]
Second point answer:
You can use .htaccess also in this case. But for this question, please bear this discussion in mind (especially my answer).