I have a page which name is pageid5.asp but in url i want to access it by page.asp?ID=5.
I try to handle it by .htaccess file but not success. My code is
RewriteEngine On
RewriteRule page.asp?ID=5 pageid5.asp
Can anyone help me
You can't access a query string in the test string of RewriteRule.
It needs to be handled this way.
RewriteEngine On
RewriteCond %{QUERY_STRING} ID=(.+)
RewriteRule ^page.asp$ pageid%1.asp [L]
Let me know how this works out.
Related
I am trying to send /bn/referral.php?id=xxxxx to https://www.newdomain.com/index.php?referral=xxxxx
I have it currently set up like this, with no luck:
RewriteRule ^/bn/referral.php?id=([0-9]+)$ https://www.newdomain.com/index.php?referral=$1 [NC,L]
Thanks in advance for any insight to this issue.
With your shown samples, attempts please try following .htaccess rules. Please make sure to clear your browser cache before testing your URLs. Also I am using here THE_REQUEST variable to handle both uri and query string together.
RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/bn/(referral)\.php\?id=(\S+)\s [NC]
RewriteRule ^ https://www.newdomain.com/index.php?%1=%2 [R=301,L]
I'm new to htaccess so please bear with me..
I'm trying to redirect traffic to URLs with query string to the root of my site as these URLs are no longer used.
Here is an example:
I would like traffic to this URL
https://www.DomainName.com/subdir1/subdir2/cond_e.asp?obark=110246
to go to http://www.DomainName.com
I do not need to keep the URL or anything just redirect to my homepage.
I need to do this for query string value from obark=110246 all the way up to obark=120000.
I've basically played around with the below to get at least one URL to redirect properly but never could get it to work at all.
RewriteCond %{QUERY_STRING} ^oPark=110246$
RewriteRule ^subdir1/subdir2/cond_e(.*) ^$? [NE, R=301, L]
What am I doing wrong? please help!
Try with below rule in subdir2,
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/cond_e.asp
RewriteCond %{QUERY_STRING} ^obark=[1]{1}[1-2]{1}[0]{1}[02-9]{1}[094-5]{1}[06-9]{1}
RewriteRule ^ http://www.DomainName.com? [R=301,L]
I want to redirect specific URL with params to another domain
http://domain.tld/buy/?w=X1234 to http://anotherdomain.tld/product.php?id=X1234
Here my htaccess
RewriteCond %{REQUEST_URI} !^/*buy/(.*)$ [NC]
RewriteRule ^/*buy/?w=([a-zA-Z0-9]+)$ http://anotherdomain.tld/product.php?id=$1 [NC,L,R=301]
but not working. maybe the problem is param ?w=
Thank you
UPDATE: i solve the problem by using Query string, after reading How to REGEX and .htaccess rewrite url
RewriteCond %{QUERY_STRING} ^w=([a-zA-Z0-9]+)$
RewriteRule ^/*buy/$ http://anotherdomain.tld/product.php?id=%1 [NC,L,R=301]
Thank you stackoverflow and folks! i m start understanding regex from here ^_^
That's right, your params won't be picked up, but they can be passed on.
Something like;
RewriteRule ^buy/([a-zA-Z0-9]+)$ http://anotherdomain.tld/product.php?id=$1 [NC,L,R=301]
Where your original url would be; /buy/X1234
I'm trying to rewrite urls like http://www.url.com/blog/?p=123 to http://www.url.com/#blog/123. I've read up on things and found that you can only parse the query string in the RewriteCond so I tried something like:
RewriteCond %{QUERY_STRING} ^p=([0-9]*)$
RewriteRule ^.*$ /#blog/%0 [NE,R]
When I try this the urls end up being rewritten to:
http://www.url.com/#blog/p=213?p=213
Any ideas how to do this properly? Also, is there a way to add an additional RewriteCond that checks that the REQUEST_URI contains blog?
You can do this by removing the query string entirely:
RewriteCond %{QUERY_STRING} ^p=([0-9]*)$
RewriteRule ^.*$ /#blog/%1? [NE,R]
This should give you:
http://www.url.com/#blog/213
If you want to check if the URL contains the term "blog" then simply check:
RewriteCond %{REQUEST_URI} .*/blog/.*
It is important to note that you will not be able to check for "blog" in links like http://www.url.com/#blog because, as noted by Patrick, everything after the # is not sent to the server.
See the Apache wiki on mod_rewrite for more information.
That may not work because browsers do not send the fragment of the url after the hash (#) with the request, so any request for http://www.url.com/#blog/p=213?p=213 will be a request for http://www.url.com/
The hash fragment is supposed to be used for anchor tags on pages, and is never sent to the server.
Try this rule in your .htaccess file:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{QUERY_STRING} ^p=(.*)$ [NC]
RewriteRule ^blog/?$ /#blog/%1? [NC,NE,L,R]
With above a URL of http://localhost/blog/?p=1234 will become http://localhost/#blog/1234
I've been using mod_rewrite in my htaccess file to rewrite my urls and I've run into a problem when doing pagination.
Here's the url for my page:
http://domain.com/concerts/features/folk-roots?page=2
htaccess file:
RewriteRule ^features/([^/]*)?page=([0-9]*)$ featureCat.php?cat=$1&page=$2 [NC,L]
It works fine without the page query, but if I want to change pages I can't figure out how to write the regular expression to grab the page #.
Any ideas would be appreciated!
You need to use RewriteCond immediately before the RewriteRule to get access to the query string:
RewriteCond %{QUERY_STRING} ^page=([0-9]*)$
RewriteRule ^features/([^/]*)$ featureCat.php?cat=$1&page=%1 [NC,L]