How to create redirect? - .htaccess

I want build redirect
from
/root/root2/query
to
http://example.com/query
I created following code in .htaccess
RewriteRule ^sorevnovania\/filter\/(.+)$ http://xn----8sb3aobdifmb0d.xn--p1ai/$1 [R=301,L]
Where I have mistake?

RewriteEngine on
RewriteBase /
RewriteRule ^sorevnovania/filter/(.*)$ http://xn----8sb3aobdifmb0d.xn--p1ai/$1 [R=301,L]
Guess it must be like that.

Related

How can I redirect old pages with question marks in the URL?

I have read about htaccess redirect and rewrite on stackoverflow and on other sites and learned how to redirect simple pages and directories, but there are about 30 links remaining that I haven't been able to redirect. The reason appears to be because they contain "?" in the link's URL. I've tried the solutions posted but I haven't been able to make enough sense of them to succeed.
These work:
Redirect /Corpfleet.php htp://www.marketyourcar.cm/wraps.php
Redirect /drivers.php htp://www.marketyourcar.cm/drivers.php
Redirect /galleries.php htp://www.marketyourcar.cm/galleries.php
These do NOT work:
Redirect /ad.php?View=FAQ htp://www.marketyourcar.cm/advertiser-faqs.php
Redirect /ad.php?View=gallery htp://www.marketyourcar.cm/galleries.php
Redirect /ad.php?View=Materials htp://www.marketyourcar.cm/products-services.php
Yes, I know that the URL above is htp and .cm - I had to break it in order to make this post with my low reputation level.
If anyone can help with this I'd appreciate it.
Thanks
If you want to redirect from like:
site.com/index.php?blabla=1&id=32
to
site.com/contact.html
then use:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} blabla=1&id=32
RewriteRule ^(.*)$ http://www.site.com/contact.html? [R=301,L]
</IfModule>
Redirect can't handle that. RewriteRule can. This should work.
RewriteEngine on
RewriteRule ^/ad\.php\?View\=FAQ$ http://www.marketyourcar.cm/advertiser-faqs.php [R=301,L]
RewriteRule ^/ad\.php\?View\=gallery$ http://www.marketyourcar.cm/galleries.php [R=301,L]
RewriteRule ^/ad\.php\?View\=Materials$ http://www.marketyourcar.cm/products-services.php [R=301,L]
Or try this:
RewriteEngine on
RewriteRule ^/ad.php?View=FAQ$ http://www.marketyourcar.cm/advertiser-faqs.php [R=301,L]
RewriteRule ^/ad.php?View=gallery$ http://www.marketyourcar.cm/galleries.php [R=301,L]
RewriteRule ^/ad.php?View=Materials$ http://www.marketyourcar.cm/products-services.php [R=301,L]
This might work:
Example:
RewriteEngine On
RewriteRule ^/ad.php?View=FAQ$ http://www.marketyourcar.cm/advertiser-faqs.php? [R=301,L]
Add a trailing ? to the substitution URL to remove the incoming query.

Redirect this url permanently with .htaccess

I am trying to permanently redirect a url but it doesn't seem to work, this is what I have in the .htaccess file
RewriteEngine on
rewriteRule ^modules\.php?name=My_Page$ http://mysite.net/mypage [R=permanent,L]
As you can see I want to redirect modules.php?name=My_Page to http://mysite.net/mypage
I appreciate any help. Thanks
The path used in RewriteRule doesn't contain the querystring. Use
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} ^name=My_Page$
rewriteRule ^modules\.php$ /mypage? [R=permanent,L]

How do i rewrite this url address

I have a URL that looks like this http://domain.com/index.php/view/test. How do i rewrite it so it doesn't have index.php/view in it. I just want it to look like http://domain.com/test. I want users to be able to type that short url directly in the browser
I tried the following in .htaccess but it's not working
RewriteEngine on
RewriteRule ^/$ index.php/view/
I'm running php 5.2.17
RewriteBase /
RewriteCond %{REQUEST_URI} !^/index.php/view/(.*)$
RewriteRule ^(.*)$ index.php/view/$1 [L]
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php/view/$1 [L]
Would do it if I understand you correctly.

htaccess 301 Redirect issue

I have the following URL structures for my website:
http://domain.com/slug/1/test-test.html
http://domain.com/slug/2/test-test.html
and i want to change it to
http://domain.com/new-1-test-test.html
http://domain.com/new-2-test-test.html
i have already tried
RewriteRule ^slug$ /new- [R=301,L]
RewriteRule ^/?my\slug /new [R=301,L]
but it does't work..
anyone know how to redirect this with htaccess?
Thanks
Try this - RewriteRule ^slug/([0-9]+)/(.*)$ /new-$1-$2 [R=301, L]
RewriteEngine On
RewriteRule ^slug/([0-9])/(.*)$ /new-$1-$2 [R-301,L]

mod_rewrite 301 redirect not working

I'm trying to set up a rewrite that will redirect this URL:
/video-2011.php?video=150
to this:
/video/150/freeform-title-text-here/
I have the rewrite working using this line in my HTACCESS:
RewriteRule ^video/([0-9]+)/(.*)$ video-2011.php?video=$1 [L]
But as soon I add R=301 into the mix, it breaks. Any ideas?
Here's the full HTACCESS when it breaks:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^video/([0-9]+)/(.*)$ video-2011.php?video=$1 [R=301,L]
Any help is greatly appreciated, thanks!
I think you might be missing a line from your .Htaccess.
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^video/([0-9]+)/([a-z0-9-_]+)$ video-2011.php?video=$1 [L]
#New
RewriteCond %{REQUEST_URI} !^/video/([0-9]+)/([a-z0-9-_]+)/?$
RewriteCond %{QUERY_STRING} ^video=([0-9]+)&name=([a-z0-9-_]+)/?$
RewriteRule ^video-2011.php$ video/%1/%2/? [R=301,L]
I assuming you want to rewrite the url if it is:
/video/150/freeform-title-text-here/
And redirect the url if it is:
/video-2011.php?video=150
to:
/video/150/freeform-title-text-here/
So this way it keeps the urls looking pretty and tidy.
Please correct me if I am wrong.
Edit
I've added in a RewriteCond to stop the second rewrite happening.
As the first rule will obviously rewrite:
/video/150/freeform-title-text-here/
Which means the query string you don't see:
/video-2011.php?video=150
Would of made the second rule happen too.
Can you try:
RewriteRule ^video/([0-9]+)/ /video-2011.php?video=$1 [R=301,L,NC,QSA]
And yes it will redirect /video/150/foo to /video.php?video=150 not the other way around as you've stated in your question.

Resources