Evening, I'm trying to do a rule to convert this:
https://example.com/pt/herbario/cons_reg_ncom2.asp?ncomum=Marmeleiro+unedo&Submit3=Pesquisar&ID=1640
into this:
https://example.com/pesquisa/ncomum/Marmeleiro+unedo
Right now I have this:
RewriteRule ^pt/herbario/cons_reg_ncom2.asp(.*)$ /pesquisa/ncomum/$1 [L, QSA]
But according to http://htaccess.madewithlove.be/ this redirects to a URL like this:
https://example.com/pesquisa/ncomum/?ncomum=Marmeleiro+unedo&Submit3=Pesquisar&ID=1640
I already tried to change to ([^&]) but with no luck ... what am I missing?
Thanks in advance
The query string is not part of the RewriteRule URI. You must use:
RewriteEngine on
RewriteCond %{QUERY_STRING} (?:^|&)ncomum=([^&]*)(?:&|$) [NC]
RewriteRule ^pt/herbario/cons_reg_ncom2\.asp$ /pesquisa/ncomum/%1? [NC,L]
Related
I need a general permament redirection rule for every
mysite.com/read.cfm?id=NUMBER
to
mysite.com/?p=NUMBER
I'm trying something like:
RewriteRule ^(.+?)\read.cfm$ /?p=$1 [L,NC,R]
Thanks in advance.
To redirect /read.cfm?id=12345 to /?p=12345 you can use :
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^read.cfm$ /?p=%1 [L,NC,R]
i am trying to change the url using htaccess rewrite
i want to change this url
page/details.php?name=abcdef&id=18
to
page/abcdef
Here my sample code for this
RewriteEngine On
RewriteRule ^company/([A-Za-z0-9-]+)/$1 company/details.php?name=$1&id=$2 [R=301,L]
this is not working, and also i was tried many code but not working,please help me to find htaccess code for this url
Thanks advance
This should do what you're after:
RewriteCond %{QUERY_STRING} ^.*name=([a-zA-Z0-9]*).*$
RewriteRule ^page/(.*)$ page/%1? [R=301,L]
Try this one:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^name=(.*)&id=(.*)$
RewriteRule ^page/(.*)$ /page/%1? [R=301,L]
This will check for these 2 parameters in the query string.
I need this logic to work:
I want rewrite this string for users to see
http://mysite.com/index.php?cl=mykeystring
to
http://mysite.com/otherkey/
http://mysite.com/index.php?myvar=test&cl=mykeystring&mysecondvar=morevalue
to
http://mysite.com/otherkey/myvar=test&mysecondvar=morevalue
But when http://mysite.com/otherkey/ is written, so load
http://mysite.com/index.php?cl=mykeystring, but no redirects will be done.
Is it possible? There are no possibility to change anything in codes, but only .htaccess
This logic is nearly realized by this code:
RewriteCond %{QUERY_STRING} ^(.*?)cl=mykeystring(.*?)$ [NC]
RewriteRule ^index.php$ /otherkey/%1%2? [R,L]
RewriteRule ^otherkey/(.*?)$ /index.php?cl=mykeystring&$1
but im getting some not needed amp symbols on first rewrite rule. any solutions?
I think you can do something like this:
RewriteCond %{QUERY_STRING} cl=mykeystring [NC]
RewriteRule ^index.php /otherkey/ [QSA]
Docs here: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
I have a dynamic query string that I need to pass via an .htaccess redirect. For example:
I need to redirect this URL: http://mysite.com/page1?action=signup&var2=dynamicVar
To this: http://mysite.com?action=signup&var2=dynamicVar
I know this is pretty simple, but I'm really not sure what type of rule/syntax would work for this.
Any help is greatly appreciated!
If you already have .htaccess then simply add this line:
RewriteRule ^page1/?$ page2 [L,R,QSA,NC]
Update: Based on your comments:
RewriteCond %{QUERY_STRING} (^|&)action=signup(&|$) [NC]
RewriteRule ^page1/?$ / [L,R,QSA,NC]
RewriteRule ^page1(.*)$ /page2$1 [L,R=301]
Input
http://mysite.com/page1?action=signup&var2=dynamicVar
this is the rewrite rule
RewriteRule ^page1?(.*)$ /?$1 [L,R=301]
redirect to
http://mysite.com/?action=signup&var2=dynamicVar
this will redirect all request o page1 with get parameters to http://mysite.com
Use %{REQUEST_URI}
fi.:
RewriteCond %{HTTP_HOST} ^website\.(.+)$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
rewrites anything that starts with "website" to "www.website..." including the querystring (by use of %{REQUEST_URI})
I have this code for my htaccess file:
RewriteEngine On
RewriteRule /([^/]+)?$ index.php?page=$1
RewriteRule /([^/]+)/([^/]+)?$ index.php?page=$1&var1=$2
RewriteRule /([^/]+)/([^/]+)/([^/]+)?$ index.php?page=$1&var1=$2&var2=$3
It works fine however when I print out the get array on index.php it ignores the first variable so i have to do something like spareslist.com/randomthing/page/var1/var2
How would I be able to use this without having to have a random variable before the others?
What about using the ^ in RewriteRule? Like this:
RewriteEngine On
RewriteRule ^([^/]+)?$ index.php?page=$1
RewriteRule ^([^/]+)/([^/]+)?$ index.php?page=$1&var1=$2
RewriteRule ^([^/]+)/([^/]+)/([^/]+)?$ index.php?page=$1&var1=$2&var2=$3