I'm trying to do a 301 redirect using .htaccess file to redirect:
http://www.mydomain.com/index.php?/knowledgebase/
To:
http://www.mydomain.com/knowledgebase/
Ive tried about 30 different redirect/rewrite suggestions but none work, can anyone provide the specific .htaccess setting I need please?
You can do this with mod_rewrite like this:
RewriteCond %{QUERY_STRING} ^/knowledgebase/$
RewriteRule ^index.php$ /knowledgebase/ [L,R=301]
Edit: When debuging htaccess rewrite rules I find this tool very useful
Related
I need to make the following redirection using htaccess (WordPress)
http://oldweb.com/pl/
to https://newweb.com/url/differenturl/
But this redirection should work only for http://oldweb.com/pl/, the urls http://oldweb.com/en/ or http://oldweb.com/il/ should not have any redirection.
My solution works but it works for /en/ and /il/ also:
Redirect 301 http://oldweb.com/pl/ https://newweb.com/url/differenturl/
I'm not a hero in rewriting, sorry :) Can anyone help me with this simple thing?
Redirect matches only REQUEST_URI not full URL with domain protocol etc.
Better to use a RewriteRule just below RewriteEngine On line in your root .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?oldweb\.com$ [NC]
RewriteRule ^pl/?$ https://newweb.com/url/differenturl/ [L,NC,R=301]
Have been struggling with a 301 redirect issue and cannot see the wood for the trees. Really hope someone can assist.
I have over 400 old urls that we need to redirect to a new urls. I have however modified the htaccess to create a clean url on the new site and am not sure if this is causing an issue or if I am doing something else wrong.
To clean urls in the new site I have added the following to the htaccess fle:
RewriteEngine On
RewriteRule ^([0-9]+) category?cat=$1 [NC,L,QSA]
This is so that instead of www.mysite/category?cat=1 I can have www.mysite/1 and-add-other-information
I am now trying to do the redirects for the 400 urls such as:
RewriteRule ^category?cat=1 1/and-add-other-information [R=301,NC,L,QSA]
RewriteRule ^category?cat=2 1/and-different-information [R=301,NC,L,QSA].
I know the L flag makes a difference and have tried this with and without.
I hope this makes sense.
QueryString isn't part of match in pattern of a RewriteRule.
You need to use RewriteCond directive and match against %{QUERY_STRING} variable like the following :
RewriteEngine on
RewriteCond %{QUERY_STRING} ^cat=1$
RewriteRule ^category$ /and-add-other-information? [R=301,NC,L,QSA]
I was wondering how it is possible to remove part of a url with htaccess for example I have a url like this:
http://localhost/item.php?pa=gd34392
now I need to use htaccess to redirect this page or anything like this to a page with this url:
http://localhost/gd34392
I have tried things like this but nothing seems to work and I do not really know my way around htaccess
RewriteEngine on
RewriteRule item.php?pa=$1 /$1 [R=301,L]
You can achieve that using the following rules in your .htaccess:
RewriteEngine On
RewriteRule ^([^/]*)$ /item.php?pa=$1 [L]
Just make sure you clear your cache before testing this.
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
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]