I am trying to create a rewrite cond in htaccess
I am trying to redirect
http://www.example.com/business/search-results.php?keywords=Animal+Business+Cards&go=Search
to
http://www.example.com/business/search results.php?keywords=Animal+Business&go=Search
or if possible remove the word "+cards" from any search queries...
what I have tried so far
RewriteEngine On
RewriteCond %{QUERY_STRING} ^Animal+Business+Cards$
RewriteRule ^(.*)$ http://www.example.com/business/search-results.php?keywords=Animal+Business [R=301,L]
also tried
RewriteCond %{QUERY_STRING} "&go=Search" [NC]
RewriteRule (.*) /$1? [R=301,L]
and this
Redirect /business/search-results.php?keywords=Animal+Business+cards&go=Search http://www.example.com/business/search-results.php?keywords=Animal+Business&go=Search
None of these working...
is it possible?
Can any one help?
Thank You in advance
Try the following code :
RewriteEngine On
RewriteCond %{QUERY_STRING} ^keywords=([^\+]+)\+([^\+]+)\+([^&]+)&go=([^&]+)$ [NC]
RewriteRule ^ %{REQUEST_URI}?keywords=%1+%2&go=%4 [NC,L,R]
Another solution
RewriteEngine On
RewriteCond %{THE_REQUEST} \?keywords=([^\+]+)\+([^\+]+)\+([^&]+)&go=([^&\s]+) [NC]
RewriteRule ^ %{REQUEST_URI}?keywords=%1+%2&go=%4 [NC,L,R]
Note : Redirect directive does not support querystrings in its old path perameter, that is why your last attempt failed. You can use %{QUERY_STRING} or %{THE_REQUEST} variable to match against urls with query strings.
Related
I am really having trouble with this Rewrite Rule
RewriteRule ^index.php?a=profile&u=(.*)$ /profile/$1 [R=301]
I want to make 301 redirect like
mysite.com/profile/USERNAME
Querystring is not part of match in RewriteRule, you need to match against %{THE_REQUEST} var in RewriteCond and then use %n to get that match :
This should be your complete htaccess :
RewriteEngine on
RewriteCond %{THE_REQUEST} /index\.php\?a=profile&u=([^\s]+) [NC]
RewriteRule ^ /profile/%1? [L,R]
RewriteRule ^profile/([^/]+)/?$ /index.php?a=profile&u=$1 [NC,L]
Try
RewriteCond %{QUERY_STRING} ^a=profile&u=(.*)$
RewriteRule ^index.php /profile/%1 [L,R]
http://my-domain.com/ppc-landing-page.php?Campaign=Boynton-Beach&AdGroup=Security%20System&Keyword=The%20Best%20Home%20Security%20System%20Company
I want this to be rewritten as
http://my-domain.com/Boynton-Beach/Boynton-Beach.php?Campaign=Boynton-Beach&AdGroup=Security%20System&Keyword=The%20Best%20Home%20Security%20System%20Company
and display the content inside ppc-landing-page.php
The idea is to get the value of Campaign query parameter and rewrite the url in the browser to
http://my-domain.com/{$_GET['Campaign']}/{$_GET['Campaign']}.php?Campaign=Boynton-Beach&AdGroup=Security%20System&Keyword=The%20Best%20Home%20Security%20System%20Company
the full query string should be there
and then it should replace the $_GET values in the ppc-landing-page.php with the values in the query string and display the content.
Try the following RewriteRule in the .htaccess of your site's document root
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} campaign=([^&]+) [NC]
RewriteRule ppc-landing-page.php %1/%1.php [R=302,L]
RewriteCond %{REQUEST_URI} !^/ppc-landing-page.php
RewriteCond %{QUERY_STRING} campaign=([^&]+) [NC]
RewriteRule ^(.*)$ ppc-landing-page.php [L,QSA]
RewriteCond %{REQUEST_URI} ^/ppc-landing-page.php
RewriteCond %{QUERY_STRING} campaign=([^&]+) [NC]
RewriteRule ppc-landing-page.php %1/%1.php [R=302,L]
Now I have put something like this...First it worked now it's not ???
I have to redirect url
http://www.nv-pedia.de/pedia/?q=node/630
to
http://www.nv-pedia.de/hafenplan-s256-arsdale/
My solutions doesn´t do anything and unfortunately i have not found an answer on this.
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)630(&|$) [NC]
RewriteRule $/hafenplan-s256-arsdale/? [R=301,L]
You can use:
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)q=node/630(&|$) [NC]
RewriteRule ^pedia/?$ /hafenplan-s256-arsdale/? [R=301,L,NC]
Firstly,Thanks for reading this. How to rewrite the url , in htaccess
For example
wwww.domain.com/home?name=MuhdNazmi <---OLD URL
wwww.domain.com/home/MuhdNazmi <---NEW URL
name is a get variables,
I dont need put .php , since it code for not showing > .php
Try:
RewriteCond %{THE_REQUEST} \ /home\?name=([^&\ ]+)
RewriteRule ^ /home/%1? [L,R=301]
RewriteRule ^home/([^/]+)$ /home?name=$1 [L,QSA]
RewriteEngine On
RewriteRule ^home/([^/]*).php$ /home?name=$1 [L]
If it is a one on redirect then you can follow the below example for you redirect
RewriteEngine on
RewriteCond %{QUERY_STRING} name=MuhdNazmi$ [NC]
RewriteRule ^home/$ /home/MuhdNazmi? [L]
If you want to define it as a generic rule for all the query string parameter modify the above code as
RewriteEngine on
RewriteCond %{QUERY_STRING} name=(.*)$ [NC]
RewriteRule ^home/$ /home/%1? [L]
I'm trying to change my .htaccess file so that if I go to:
http://www.example.com/index.php?login=true, it goes to http://www.example.com/login.
I currently have this code which removes index.php (which makes the above looks like http://www.example.com/?login=true).
RewriteEngine On
#remove index.php
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{THE_REQUEST} !/system/.*
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
RewriteCond %{THE_REQUEST} ^GET
I would setup your rewrite rule the other way around:
RewriteEngine On
RewriteRule ^login$ /index.php?login=true
This way if a user browses to http://yourserver.com/login the actual page used is http://yourserver.com/index.php?login=true, but the first URL is shown in the browser. I assume this is what you are trying to achieve.
If you really need to do it in the direction you asked for, you can try something like this:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^login=true$
RewriteRule ^index\.php$ /login [L,R=301]
This will fail of there are additional query parameters.
If you want to redirect http://yourserver.com/index.php to http://yourserver.com you can simply add the following rewrite rule:
RewriteRule ^index\.php$ / [L,R=301]
The following should work although there might something wrong with the line to exclude /system/*. Try testing with that commented out.
RewriteEngine On
RewriteCond %{QUERY_STRING} ([^=]*)=true [NC]
RewriteCond %{THE_REQUEST} ^/system/.*
RewriteRule index.php /%1? [R=301,L]
The following page helped: http://wiki.apache.org/httpd/RewriteQueryString
This tester is cool but does have a few bugs in it: http://martinmelin.se/rewrite-rule-tester/
try the following in the .htaccess in root directory of example.com
RewriteEngine On
RewriteBase /
#rewrite http://www.example.com/anything to http://www.example.com/index.php?anything=true
RewriteCond %{REQUEST_URI} ^/([-a-zA-Z0-9]+)$ [NC]
RewriteCond %1 !system [NC]
RewriteRule . index.php?%1=true [L]
#301 redirect requests for example.com/index.php?anything=true to example.com/anything
RewriteCond %{REQUEST_URI} ^/index\.php$ [NC]
RewriteCond %{QUERY_STRING} ^([^=]+)=true$ [NC]
RewriteRule . /%1? [L,R=301]
You need to check for the QUERY_STRING in a RewriteCond. I think this should do:
RewriteEngine On
#remove index.php
RewriteCond %{QUERY_STRING} ([^=]*)=true [NC]
RewriteCond %{THE_REQUEST} !/system/.*
RewriteRule ^index\.php /%1? [R=301,L]
This should redirect anything which has index.php?=true to /action