Apache redirect if no parameters - apache

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

Related

Redirect permanent doesn't works

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]

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.

mod_rewrite redirect specific .asp pages back to original server

I need to redirect traffic for a section of a redeveloped site back to the original site with apache mod_rewrite rules. I need to redirect all requests starting with http://www.example.com/page.asp back to the original site http://www.original.com/page.asp with the query string or anything following page.asp intact.
This seems simple enough, however I have had no luck with mod_rewrite generators or documentation on the web. My latest stab at the problem looks like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^http://www.example.com$ [NC]
RewriteRule ^page\.asp(.*)$ http://www.original.com/page\.asp$1 [R=301,NC]
I appreciate any insight into correcting this mod_rewrite rule. Other redirects are working fine.
I was able to get the rewrite to function properly using:
RewriteRule ^/page(.+) http://www.original.com/page$1 [R=301,NC,L]
I found this apache doc helpful: Resource Moved to Another Server

UrlRewrite & Redirect with an optional /XX/home part in Apache2

For a perfect working and Error404-Free log file, I have to redirect all previous (now wrong) home page urls to the new homepage. For that I have a partially working rewrite:
RewriteRule ^home$ /en/aster [R=301]
// Works for site.com/home but NOT for site.com/en/home or site.com/xx/home etc.
Q1. How to make an optional part ?????/ sothat site.com/anything/home permanently redirects to site.com/anything/home making sure that the root is not another folder but the actual real sites root followed by the two language chars then /home?
Q2. for consistency and SEO purposes, Do I need a [R=301] or a [R=301,L] ?
Your ideas and help is highly appreciated.
Not sure if I completely understand what you want the site.com/anything/home to redirect to, but this is how I understood:
RewriteRule (.*)/home $1/en/aster [R=301,L] Will match all requests ending in "/home". The (.*) will keep the urls in the same path. Therefore site.com/anything/home redirects to site.com/anything/en/aster
As far as SEO, there is no difference between [R=301,L] and [R=301]. The L informs mod_rewrite to not process any further rules, which in this case is what you would want, since you are redirecting to a new page.
Hope this helps.

Apache Rewrite/Redirect different for TLD vs directory

I've migrated the content of a site from one domain to another. I have .htaccess Rewrite set up successfully to redirect any request to the old domain to the same location on the new domain, which is working fine, using the following code:
RewriteEngine On
rewritecond %{http_host} ^roundeltable.com
rewriteRule ^(.*) http://wheelspin.tv/$1 [R=301,L]
However, I want to go a little further. When somebody simply requests the old TLD (http://roundeltable.com/) I want them to be redirected to a specific page within the new domain (http://wheelspin.tv/rt). If they make a request to any other location from the old domain (for example, http://roundeltable.com/about) I want them to be sent to that exact same place at the new domain (http://wheelspin.tv/about) the way they currently are now.
Is this possible? If so, how?
So I've found the solution to this issue, which ended up being provided by somebody from Media Temple's service department. Here's the entire code required in the .htaccess file to make this work:
RewriteEngine On
RewriteRule ^$ http://wheelspin.tv/rt/ [L]
RewriteRule ^(.*)$ http://wheelspin.tv/$1
Obviously substitute whatever domain you want to redirect to in place of mine, but that's the solution for my example. Thanks for the help!
If you want to see all the details on my solution, I have it here: christiaanconover.com/media-temple-service-rocks/