Redirect 301 issue - .htaccess

i´m trying to do a 301 redirect in my .htaccess with the following lines:
Options +FollowSymLinks
RewriteEngine On
Redirect 301 /oldpage http://www.myhomepage.de/newpage/
The problem is, that the redirected url looks like this:
http://www.myhomepage.de/newpage/?it=oldpage
and that naturally causes a 404 on my site.
Does anybody know, what the problem could be?
Thanks a bunch!

This should work for you:
RewriteRule ^oldpage$ newpage? [R=301,L]
The question mark at the end of the destination will tell it to use a blank query string.
The above assume the pages are on the same domain. But if you're moving to another domain, this should do the trick:
RewriteRule ^oldpage$ http://newdomain.tld/newpage? [R=301,L]

Related

How to create a vanity url

I would like to know how to create a vanity url for a website.
Ideally I would like to be able to put this on a flyer:
www.charity.org.uk/monthlydonation
and when that is entered, it will go off to:
www.charity.org.uk/donate/monthly-donation.php
I've been reading about vanity urls, redirects and rewrites but quite frankly I'm not even sure what I need to do this?
I tried the following in a .htaccess file:
RewriteEngine On
RewriteBase /
RedirectMatch 301 /monthlydonation /donate/monthly-donation.php
but got an error message saying there was a redirect loop.
All time and help is greatly appreciated.
Try using mod_rewrite instead, RedirectMatch is part of mod_alias and processes the request separate from mod_rewrite:
RewriteEngine On
RewriteBase /
RewriteRule ^monthlydonation$ /donate/monthly-donation.php [L]
Additionally, the reason why you're getting a redirect loop is that RedirectMatch expects a regex and not just a path. So /monthlydonation is the matching pattern, and that happens to also match the redirect's target: "/donate /monthly-donation.php".

301 redirect .htaccess parameter php?fr_xyz to php?en_xyz

1st i have to say: i tried google of course. so many tips about my request - but i dont get it. maybe you can help...
it sounds simple: i want a 301 via .htaccess to a another parameter file
for example:
www.mydomain.tld/ runs without .htaccess to www.mydomain.tld/index.php?de_xyz
but:
what i want is, if you call www.mydomain.tld you get to www.mydomain.tld/index.php?en_xyz
-> ?de to ?en
if i try a simple: Redirect 301 /index.php http://www.mydomain.tld/index.php?xyz i get a redirection error on this side.
i have tried so many ways. dont get it :/
thx for your answer
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} !(^|&)en_xyz(&|$) [NC]
RewriteRule ^/?$ %{REQUEST_URI}?en_xyz [L,QSA,R=302]
Have you tried
RewriteRule ^/?$ /index.php?en_xyz [R=301]
Note that 301 is a permanent redirect so the browser might not re-read your configuration if you redirect to a wrong address by mistake while trying.
If not working you might want to add
RewriteLog "/some/path/rewrite.log"
RewriteLogLevel 3
to your vhosts file if you have access (it might not work in .htaccess) and get the details from log.
By the way I'd prefer handling this in index.php:
header('Location: index.php?en', true, 301);

RewriteRule .htaccess

I'am trying to update .htaccess to redirect me from : page.php/name to page.php?id=name. Can anyone help with example? I find a lot of example but not for this case.
To redirect (telling the browser that the request for page.php/name is at page.php?id=name, thus changing the URL in the location bar) you can do one of two things.
Using mod_alias:
RedirectMatch 301 ^/page\.php/(.*)$ /page.php?id=$1
Or using mod_rewrite:
RewriteRule ^/?page\.php/(.*)$ /page.php?id=$1 [QSA,L,R=301]
If you don't want a permanent redirect (301), then remove the 301 and =301 parts from the above.

.htaccess Rewrite Questions

I need to redirect a dynamic url to another url, with the dynamic portion intact, for example:
http://www.mydomain.com/VARHome.aspx?var=32
needs to redirect to:
To: http://www.otherdomain.com/VARHome.aspx?var=32
The value after "var=" is dynamic, it can be any number.
This needs to be done via .htaccess.
Thanks for any help!
I'm thinking RewriteRule ^(.*)$ http://www.otherdomain.com/$1 [R=301,L] or something along those lines should do the job.
Edit: Maybe something like
RewriteRule ^VARHome.aspx?var=(.*)?$ http://www.otherdomain.org/VARHome.aspx?var=$1/ [R=301,L]
if you are in mydomain.com, write in .htaccess
RewriteEngine on
RedirectMatch 301 ^/VARHome.aspx?var=(.*)$ http://www.otherdomain.com/VARHome.aspx?var=$1

sub domain htaccess redirect to HTTPS URL

I've been trying to redirect my subdomain buynow.mydomain.info to the product link which is https://www.2checkout.com/checkout/purchase?sid=******&quantity=1&product_id=1.
I tried the simple .htaccess line
Redirect 301 / https://www.2checkout.com/checkout/purchase?sid=******&quantity=1&product_id=1
but it doesn't work, it only redirects to https://www.2checkout.com/checkout/purchase without mentioning my product as it ignores the rest of the URL ?sid=******&quantity=1&product_id=1
I thought it might be a problem with the link which is HTTPS, but I can't solve it, I hope you guys could help me, thanks.
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) https://www.2checkout.com/checkout/purchase?sid=******&quantity=1&product_id=1 [R=301]

Resources