Someone linked to my site from nice place but the moron type the wrong URL, he did %20 at the end of it (probably his site did that). So I want to redirect http://example.com/%20 to http://example.com, because http://example.com/%20 is of course going to http://example.com/404 cuz that one is not valid URL.
I tried this:
rewriterule ^%20(.*)$ http://example.com$1 [r=301,nc]
But it just doesn't work. Looks like the % character has to be somehow escaped or something. So i tried also
rewriterule ^\%20(.*)$ http://example.com$1 [r=301,nc]
to give the % its original meaning by escaping it but it doesn't seem to be working either. Also read htaccess to escape percent (%) from URL but the solution presented there doens't seem to be working either. Anyone has idea how to do this? Thanks so much.
You can match %20 in RewriteRule using \x20:
RewriteRule ^\x20(.*)$ /$1 [R=301,L,NE]
Related
Ahoy all, I know these questions have been beaten to death. And even after my hour of research on stack, none of the suggestions or answers I have attempted have worked.
The only thing I am needing to do is....
Take the variable from a URL and redirect to another page (site), inserting that variable accordingly.
Keep in mind the variable can contain letters, dashes, underscores or numbers.
Original
/directory-here/a-random-name.php?strPropID=13d3-1
and I am redirecting to another domain.
http://www.someotherdomain.com/redirect.php?strPropID=13d3-1
So now I have this:
RewriteRule ^/directory-here/a-random-name.php\?strPropId=(.*)$ http://www.someotherdomain.com/redirect.php?propid=$1 [R=301,L]
However the redirect isn't working. What am I doing wrong here? I know it has to be something simple, no?
Thanks in advance!
You need to match query string using a RewriteCond not in RewriteRule:
RewriteEngine On
RewriteCond %{THE_REQUEST} /directory-here/a-random-name.php\?strPropId=([^\s&]*) [NC]
RewriteRule ^ http://www.someotherdomain.com/redirect.php?propid=%1 [R=301,L,NE]
i am trying to redirect http://domain.com/partners/index.php?00N600000028zDp=0016000000qp33G&00N60000002UzF5=0016000000qp33G&00N600000029PAh=0016000000qp33G&00N6000000292kr=GO%20GREEN%20AMERICA%20TV&00N60000002X3cq=1$
to another page. typically i would do this as such:
RewriteRule ^partners/index.php?00N600000028zDp...(shortening this)$ http://domain.com/page/ [L,NE,NC,R=302]
however this time it's not working. i suspect it has something to do with the ?,=,&, or % characters in the URL, but i am not sure. any advice? thank you.
You can't match against the query string (everything after the ?) in the regex pattern in a RewriteRule. You need to match against the %{QUERY_STRING} variable:
RewriteCond %{QUERY_STRING} ^00N600000028zDp=0016000000qp33G&00N60000002UzF5=0016000000qp33G&00N600000029PAh=0016000000qp33G&00N6000000292kr=GO%20GREEN%20AMERICA%20TV&00N60000002X3cq=1$
RewriteRule ^partners/index.php$ http://domain.com/page/? [L,NE,NC,R=302]
Keep in mind that when you redirect the browser, the browser will load http://domain.com/page/ and this redrect that you've setup doesn't touch that at all. So you'll see the contents of http://domain.com/page/ once you get redirected.
i would like simply to create a 301 redirect, but my code does'nt work and returns a beautiful 404 page (-_-).
I think the problem is the "?" in the from url, i tried to escape it but it doesn't work anymore.
RewriteRule ^produit.php?PDT_ID=473 /product.php?id_product=210 [R=301]
Thanks to take a look
It's a common mistake. As the docs say, to test for things in the query string, you need to use a RewriteCond directive, like this:
RewriteCond %{QUERY_STRING} PDT_ID=473
RewriteRule ^produit.php /product.php?id_product=210 [R=301]
Which means "if the query string matches the pattern 'PDT_ID=473', and the pattern matches the uri, then rewrite". Note that you might want to make the rewriteCond's regex more foolproof to ensure it won't match things like APDT_ID=4735 as well, but this should get you started.
I'm trying to mask a part of my url using .htaccess but I'm having several issues
my url is
http://ristorantitalianetwork.com/ristorantitalianetwork.com/admin/
I'd like to remove the duplicate ristorantitalianetwork.com, so I'd like that my url will be like
http://ristorantitalianetwork.com/admin/
I've used
RewriteRule ^ristorantitalianetwork.com/([^/]*)$ ?q=$1 [L]
but it doesn't work
Could you please help me to figure out how to solve this problem?
Thanks a lot
Best regards
You really need
RewriteRule ^/admin$ /ristorantitalianetwork.com/admin [L]
Bear in mind that the URL you should expose to users is http://ristorantitalianetwork.com/admin/ which will then internally get converted (rewritten) to http://ristorantitalianetwork.com/ristorantitalianetwork.com/admin/.
It is not the other way round as many believe.
You almost did it! But...
In your question, your rewriterule says that it is applied on URLs that don't end with a slash (/). And you say you want to rewrite some URLs... and give URLs examples with a slash (/).
If you need to do a real redirect (i.e. the URL in the browser changes):, here's the good rewriterule:
RewriteRule ^ristorantitalianetwork\.com/([^/]*)/$ /$1 [QSA,R=301,L]
If you need to do only internal redirect:
RewriteRule ^ristorantitalianetwork\.com/([^/]*)/$ /$1 [QSA,L]
Keep in mind that the URL must end with a slash (/).
I am trying to rewrite this url and it just doesn't seem to be working and I am unclear what is going wrong
I want this URL:
www.mysite.com/dvd-123/Studio/studio_name.php?thumbs=yes&order=price
To actually send to:
www.mysite/cat/list_products.php?studio=123&store=dvd&thumbs=yes&order=price
Here is what I have that is sorta working:
RewriteRule ^dvd-([0-9]+)/Studio/(.*)\.php?(.*)$ cat/list_products.php?studio=$1&store=dvd&$3 [L]
The results I am receiving are the same as if i want to:
www.mysite/cat/list_products.php?studio=123&store=dvd
ignoring the:
&thumbs=yes$order=price
Thank you in advance for your help!
From Apache documentation:
The Pattern will not be matched against the query string... To combine a new query string with an old one, use the [QSA] flag.
I haven't tested this, but hopefully it should point you in the right direction.
RewriteRule ^dvd-([0-9]+)/Studio/(.*)\.php$ cat/user_list_products.php?Manname=$1&store=dvd [L,QSA]
You need to escape the slashes.
RewriteRule ^dvd-([0-9]+)\/Studio\/(.*)\.php?(.*)$ cat/user_list_products.php?Manname=$1&store=dvd&supersale=$3 [L]