How can I rewrite this type of URL:
https://example.com/assets/forms/vanilla/index.php?property=cus_F8fylX6aITpJOR
to have something like this:
https://example.com/forms/cus_F8fylX6aITpJOR
How can I access to the property and vanilla parameters after ?
Thanks.
You can use RewriteCond %{QUERY_STRING} to mateh the query string
Something like that :
RewriteCond %{QUERY_STRING} property=(\w+) [NC]
RewriteRule ^assets/forms/([a-zA-Z]*)/index.php /forms/%1?$1 [L]
Related
i wish to add more url variables to my url... whatever there is after ? i wish to retrieve it as a urls variable Thank YOU!
RewriteRule ^(.*).html?(.*)$ products.cfm?categ=$1&urls=$2 [NC,L]
RewriteRule ^products.cfm?categ=(.*)&urls=(.*)$ (.*).html?(.*) [NC,R=301,L]
RewriteCond %{QUERY_STRING} ^condition=(\d+)&maxprice=(\d+)&minprice=(\d+)&persons=(\d+)&maxyear=(\d+)&minyear=(\d+)&order=(\d+)$ [NC]
RewriteRule ^category/(.*).html$ products.cfm?categ=$1&condition=%1&maxprice=%2&minprice=%3&persons=%4&maxyear=%5&minyear=%6&order=%7? [NC,L]
I have a lot of working mod_rewrite rules already in my httpd.conf file. I just recently found that Google had indexed one of my non-rewritten URLs with a query string in it:
http://example.com/?state=arizona
I would like to use mod_rewrite to do a 301 redirect to this URL:
http://example.com/arizona
The issue is that later on in my rewrite rules, that 2nd URL is being rewritten to pass query variables on to WordPress. It ends up getting rewritten to:
http://example.com/index.php?state=arizona
Which is the proper functionality. Everything I have tried so far has either not worked at all or put me in an endless rewrite loop. This is what I have right now, which is getting stuck in a loop:
RewriteCond %{QUERY_STRING} state=arizona [NC]
RewriteRule .* http://example.com/arizona [R=301,L]
#older rewrite rule that passes query string based on URL:
RewriteRule ^([A-Za-z-]+)$ index.php?state=$1 [L]
which gives me an endless rewrite loop and takes me to this URL:
http://example.com/arizona?state=arizona
I then tried this:
RewriteRule .* http://example.com/arizona? [R=301,L]
which got rid of the query string in the URL, but still creates a loop.
Ok, adding the 2nd RewriteCond finally fixed it - now rewriting correctly and no loop:
# redirect dynamic URL: ?state=arizona
RewriteCond %{QUERY_STRING} state=arizona [NC]
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteRule .* http://domain.com/arizona? [R=301,L]
# older rewrite rule that passes query string based on URL:
RewriteRule ^([A-Za-z-]+)$ index.php?state=$1 [L]
And here's the code to make it work for any state value, not just arizona:
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteCond %{QUERY_STRING} ^state=([A-Za-z-]+)$ [NC]
RewriteRule .* http://domain.com/%1? [R=301,L]
RewriteCond %{REQUEST_URI} ^/\?state=arizona$ [NC]
should be
RewriteCond %{QUERY_STRING} state=arizona [NC]
The request_uri ends at the ? token.
I have the following rewrite rule in place:
RewriteRule ^register/?$ /fitch/index.php?cmd=register [NC,L,QSA]
Requests to mysite.com/register are rewritten to
mysite.com/fitch/index.php?cmd=register
I want to allow an optional parameter to be passed as well, such that requests to
mysite.com/register/sender=models directs me to
mysite.com/fitch/index.php?cmd=register&sender=models
Perhaps:
RewriteRule ^register/(.*) /fitch/index.php?cmd=register&$1
For any number of paths -> query string params:
RewriteCond %{REQUEST_URI} ^/register/
RewriteRule ^(.*)/(.*)$ /$1&$2 [L]
RewriteCond %{REQUEST_URI} ^/register&
RewriteRule ^(.*)$ /fitch/index.php?cmd=$1 [L,QSA]
This will rewrite URL's like:
http://mysite.com/register/a=b/1=2/c=d
to:
http://mysite.com/fitch/index.php?cmd=register&a=b&1=2&c=d
I have a URL like
www.testwebsite.com?param1=abc
or
www.testwebsite.com/?param1=abc
I need to redirect to
www.testwebsite.com/level1/xyz.html?customparam=123¶m1=abc
I tried working on rewrite url but i am still new to this and need some help to achieve the solution
This is what i did till now
RewriteCond %{QUERY_STRING} param1=(.+)
RewriteRule ^/$ /level1/xyz.html?customparam=123¶m1=%1 [R=301,L]
Try adding the following to the .htaccess file in the root directory of your site.
Only param1 will be captured and passed through, other query string params will be dropped.
RewriteEngine on
RewriteBase /
#if the param1 parameter is present
RewriteCond %{QUERY_STRING} (^|&)(param1=([^&]+))(&|$) [NC]
#redirect
RewriteRule ^$ level1/xyz.html?customparam=123&%2 [L,R=301]
Im trying to forward this url, but its not working - here is my code:
RewriteRule ^https://www.wsjwine.com/discovery_offer.aspx?promo=2227006$ https://www.wsjwine.com/discovery_offer_lp2.aspx?promo=2227006 [L]
With RewriteRule directive you can only test the URL path. For further tests you need to use additional RewriteCond directives.
Now if you want to rewrite every request of /discovery_offer.aspx to /discovery_offer_lp2.aspx regardless of how the query looks like, you can just use this (example for the .htaccess file in the root directory):
RewriteRule ^discovery_offer\.aspx$ discovery_offer_lp2.aspx [L]
If you don’t specify a query in the substitution, the originally requested query is automatically appended to the new one.
And if you just want to rewrite that specific URL, try this:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} =www.wsjwine.com
RewriteCond %{QUERY_STRING} =promo=2227006
RewriteRule ^discovery_offer\.aspx$ discovery_offer_lp2.aspx [L]
You can't detect query strings like that. Use RewriteCond %{QUERY_STRING}.