Redirect 301 using .htaccess - .htaccess

I need to redirect from page
http://masterkanz.com.ua/index.php?route=product/category&path=79_103
to
http://masterkanz.com.ua/pishushchie-prinadlezhnosti/ruchki-sharikovye
Rule like
Redirect 301 /index.php?route=product/category&path=79_103 http://masterkanz.com.ua/pishushchie-prinadlezhnosti/ruchki-sharikovye
doesnt works. I read that problem can be in symbol "?". But what should I do?

Try this,
RewriteEngine On
RewriteCond %{QUERY_STRING} ^route=product/category&path=79_103$
RewriteRule ^index\.php/?$ http://masterkanz.com.ua/pishushchie-prinadlezhnosti/ruchki-sharikovye? [R=301,L]
I've tried this and it is working, you need to use {QUERY_STRING} to get the rule working.
I hope this helps.

Related

htacess redirect from php page to a different website?

This seems so trivial but I can't seem to get it to work. I'm trying to redirect
http://website.com/something/file.php?var=1
to
http://website2.com/something/$1/
I've tried a bunch of things the latest was
Redirect 301 ^file.php\?var=([0-9]+)$ http://website2.com/something/$1/
I've even tried doing
Redirect 301 ^something/$ http://website2.com/something/1/
but that didn't work either. The only thing that I've gotten to work is a redirect on the whole site doing
Redirect 301 /$ http://website2.com/something/1/
Is there something I'm missing? I've done a lot of redirects in my day but this one is throwing me for a loop. I've even used htaccess checker that said my url matches my string but it didn't actually do anything.
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /something/file\.php\?var=(\d+) [NC]
RewriteRule ^ something/%1? [R=302,L,NE]
RewriteRule ^something/(\d+)/?$ something/file.php?q=$1 [L,QSA,NC]

htaccess 301 redirection not working

In my site I want to redirect with http://domain_name.com/blog to http://domain_name.com/news and it should be work with the following criteria also
http://domain_name.com/blog/2012/06/06//blog_title to http://domain_name.com/news
http://domain_name.com/blog/blog/?cat=2 to http://domain_name.com/news
How would I do this?
Can't test that, but anyway...
RewriteEngine on
RewriteRule /
RewriteRule ^/blog/.*$ /news/ [L,R=301]

htaccess redirect a url with a param and remove duplicates

I have this url
http://www.mmametals.com.php5-20.dfw1-1.websitetestlink.com/?page_id=61
and i want to redirect to the root like this
http://www.mmametals.com.php5-20.dfw1-1.websitetestlink.com
here is my htaccess
RewriteEngine on
redirect 301 /?page_id=61/ http://www.mmametals.com.php5-20.dfw1-1.websitetestlink.com
but nothing is happening...any ideas
Also I was wondering if there is a way also in .htaccess to delete a duplicate /about ...so for example if the url is
http://somesite.com/about/about
it will rewrite the rule to always be
http://somesite.com/about
RewriteEngine On
RewriteCond %{QUERY_STRING} ^page_id=61$
RewriteRule (.*) http://www.mmametals.com.php5-20.dfw1-1.websitetestlink.com? [R=301,L]
RewriteCond %(REQUEST_URI) ^/about/about[/]?
RewriteRule (.*) http://somesite.com/about? [R=301,L]
should do it.
I don't know the exact answer off the top of my head as I don't work directly with apache that much any longer, but I think you need to look into apache's mod_rewrite module. Try taking a look at:
Apache's mod_rewrite documentation
This post about blocking certain URLS

301 Redirect. Need help. Having a hard time

I'm trying to use mod_rewrite to redirect URLs and can't get anything to work. Here is what I'm hoping to do:
Old URL:
http://www.example.com/asp.pl?_puri=astore.amazon.com%2Fthegi02-20%2Fdetail%2FB0001L0DFA%2Fassid
Needs to redirect to:
www.example.com
Anyone know of any way to do that?
Redirect and all the other Redirect* directives do only work with the URL path. So you cannot test the query.
But with mod_rewrite you can:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^_puri=astore.amazon.com&thegi02-20&detail&B0001L0DFA&assid$
RewriteRule ^asp\.pl$ http://www.example.com/ [L,R=301]

.htaccess: how to only rewrite .php URL?

My rewriterule with a condition is working fine as below:
http://www.sitename.com/index.php?n=text redirects to
http://www.sitename.com/pages/text
and the page renders properly, however, there is a problem that with the redirected URL the arguments are also added to the URL. So actually in address bar it looks like-
http://www.sitename.com/pages/text?n=text
Could anyone help me on this? The htaccess code is given below.
RewriteCond %{QUERY_STRING} ^n=(.*)$
RewriteRule index.php http://www.sitename.com/pages/%1 [r=301,nc]
You probably want to catch "index.php.*". Otherwise mod_rewrite only replaces the "index.php" part of the URL "index.php?n=text" with the new URL.
Guss,
From what you suggested, i reconstructed it as follows:
RewriteCond %{QUERY_STRING} ^n=(.*)$
RewriteRule index.php.* http://www.sitename.com/pages/%1 [r=301,nc]
This doesnt seem to be working either. Can you please elaborate on what you have said?
thank you
aditya
donĀ“t use the url in the rewrite rule, apache then sends a http 200 code and then the 301...
try sth. like this:
RewriteRule (index\.php)(?n=)(.*) /pages/$3 [r=301]

Resources