Redirection in .htaccess? - redirect

I’d like to change the URL where a user is redirected after he submits a form.
In the .htaccess I wrote this:
Redirect 301 /component/virtuemart/user/edit?Itemid=0 https://www.monsite.fr/component/virtuemart/cart?Itemid=0
But it doesn’t work…
I tried:
RewriteRule ^/component/virtuemart/user/edit?Itemid=0$ https://www.mon-site.fr/component/virtuemart/cart?Itemid=0 [R=301,L]
And it’s not working neither…
What mistakes did I do?
How could I manage that?
Thanks for your help
Paul

Related

Redirect 301 after domain change

I had to do a domain change on a website so I moved from www.mydomain.it to www.mydomain.eu. At the moment I don't have full control on the .it domain so when it was the time to make the domain change I asked the hosting provider to make a 301 redirect of the .it to the .eu so as a result, I got all the pages of the .it website redirected to my .eu's homepage (no 404 errors) because the previous website used queries as pages' URLs.
This is a link example of the previous website:
http://www.mydomain.it/index.php?page=lkr_pg_chisiamo
So what I started getting after the redirect was:
https://www.mydomain.eu/index.php?page=lkr_pg_chisiamo
which gave me back the homepage content as a result and not a 404 error.
The old website had at least 10k links like that one so each of them started having the behavior of the link above, I got the homepage content for all links. In the beginning, I thought it was a good thing for me because I wasn't getting 404 errors but then I started digging around on the web and I found out to not be a good practice because all links might be recognized as soft 404 errors.
Obviously before I made the domain change I had created all the 301 redirects of the most important pages of the website like this:
RewriteCond %{QUERY_STRING} ^page=lkr_pg_chisiamo$
RewriteRule ^(.*)$ https://www.mydomain.eu/chi-siamo/? [R=301,L]
RewriteCond %{QUERY_STRING} ^page=lkr_pg_contattaci&form_key=25-8124355$
RewriteRule ^(.*)$ https://www.mydomain.eu/contatti/? [R=301,L]
And so on..
Obviously, I didn't do that for all the 10k pages, but just the most important, so the other links are still pointing to the homepage content.
After I did this, I told Google I had changed the domain through the Google Search Console.
After a few weeks, I started seeing some results on Google but after one month I'm not still happy with them, I think I lost rank on Google. I know it could take a while more to do everything and that I should probably lose 3% of my "domain juice" after a domain change but what I was wondering if I have done everything in the right way in order to not lose rank.
My concern now is about all the links that I wasn't able to redirect and that has been redirected automatically and started getting the homepage content. Should I be worried about them?
How should I manage them?
Should I redirect them to another page which is not the homepage?
If yes, is there a way to redirect all those links (just those) even though I have all the other redirects in my .htaccess file?
Was there a better way to redirect all the 10k links of that type? How would I be able to do that?
You asked this 6 months ago, but i hope i can help you.
Add this to your .htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain\.it$ [NC]
RewriteRule ^(.*)$ http://mydomain.eu [R=301,L]
This should redirect all links to your new domain.
About Google Search Console, take a look here: https://support.google.com/webmasters/answer/93633?hl=en
About changing domain, look at: https://support.google.com/webmasters/answer/6033049?hl=en
Hope this helps!
Brhaka

Redirecting old joomla 1.5 no SEF urls to new 2.5 SEF url before index.php strip

Im working in a new 2.5 joomla site and the old site was 1.5, the urls from the old site are no SEF. I need to redirect the old 1.5 no SEF urls to the new SEF urls, im doing this:
redirect 301 /index.php?option=com_k2&v... http://www.newsite.com/es
(Note the language in the url, its seem to be important for the problem, im using the joomla integrated language system)
But its not working, somehow joomla strips the index.php and the redirect doesnt work. I try to strip the index.php from the redirect, buts its doesnt work either. Im a noob in htaccess and redirects and im stuck in this... Thank you.
Well, like this seems to be a hard problem, i think i just found a solution doing extensives testing and googling...
I found a rewrite and put it before the joomla rewrites:
RewriteCond %{QUERY_STRING} ^(.*)lang=es$
RewriteRule ^(index\.php)?$ /es? [R=301,L]
This replace the normal redirect 301.
Its hard for me to explain because i dont have too much knowledge about redirections and htaccess, the important think is that it seems to work for my problem, i hope other people just found this helpful.
If someone can explain the sintaxis of this code it will be grate.
Thank you very much.
The best thing to do is perform a complete redirect (without the query parameter i.e Redirect 301 / http://newsite.com/) and handle the query term on your new site with an SH404sef extension. http://extensions.joomla.org/extensions/site-management/sef/10134

How do I redirect an .aspx url to a php page?

How do I redirect an .aspx url to a php page?
I have links from my old site being domain.com/song.aspx?SongID=1 which I'd like to redirect to a domain.com/song.php?SongID=2 file. Can you someone tell me how to do this?
I'm open to either using htaccess or a plugin. If I use a plugin, I need to be able to have the song.php also get the querystring after song.aspx.
Htaccess is probably the best way to go. This rule is pretty general, but should do the trick.
RewriteRule ^song\.aspx$ song.php [R=301,QSA,L]
QSA stands for "Query String Append" and will append the query string from the old URL to the new URL.
If you need to match against the query string and change ID's like in your example:
domain.com/song.aspx?SongID=1 which I'd like to redirect to a domain.com/song.php?SongID=2
You'll need to setup a list of rewrites for that:
RewriteCond %{QUERY_STRING} ^SongID=1$
RewriteRule ^/?song\.aspx$ /song.php?SongID=2 [R=301,L]

301 redirect not working (server fault)

I'm a beguinner and I don't know much about web programming and different ways to do redirect.
I'm trying to do a 301 redirect from an old site to a new site, for seo purpose. My problem is that the old site is not hosted on regular hosting, but on http://pages.videotron.com/duclosma/controlemd.html .
Therefor, regular 301 redirect with the .htaccess doesn't seem to work.
Do you guys have any solution on how to do a proper redirect?
Thanks
You could do a Javascript redirect.
At the top of the page(s) You want to redirect.
window.location = "http://yournewsite.com";
Show the htaccess file your attempting to use what are the conditions you are trying?
Also as an alternative though won't give you the code for 301/302 is the good ol fashion meta based refresh assuming you have access to the html file above.
<meta http-equiv="refresh" content="3; url=http://mynewsite.com/">
Also theres other concepts if you have access to the files on the server where the original page was hosted. You could if you have access to the files, is delete them from the server drop a htaccess that acts as a catch-all redirects everything to a php file, where the php file redirects with headers in it similar to how Wordpress handles its htaccess. All in all though it depends on what rights you have over the location of that hosted old site. As you need to make sure any htaccess, or anything else you put is on the same server that its on to redirect to the new server.
EDIT
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourolddomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.yournewdomain.com/$1 [R=301,L]

htaccess rewrite one file type with get variables

i think header is confusing, here is the situation.
i host some video files and want to use on my website. but only on my website. if you realized facebook did this. but we dont have servers like them -nginx i guess-.
finally i want to redirect all requests to a certain page. like that
if someone request that
http://www.blabla.com/videos/1.mpg?hash=12345&expire=1234567
htaccess redirect that request to
http://www.blabla.com/check.php?file=videos/1.mpg&hash=12345&expire=1234567
but also if someone type
http://www.blabla.com/videos/1.mpg
it is also redirect to check.php
http://www.blabla.com/check.php?file=videos/1.mpg
RewriteCond %{QUERY_STRING} ^hash=(.*)$
RewriteRule ^(.*)/videos/(.*)$ /check.php?file=videos/$2 [R=302,L,QSA]
Now your rewriteRule will only be applied if query string contains hash=xxxxx
use R=301 if you want users to be redirected permanently