I am trying to replace & with & in my url via the .htaccess file using the following code:
RewriteRule ^(.*)&(.*)$ /$1&$2 [L,R=301]
The context is that I am using woocommerce, the user accesses an order review page (/checkout/order-pay/1111/?pay_for_order=true&key=wc_order_569cda450dc6a), which sends them to our company payment portal, however the returned url is coming back as:
/checkout/order-pay/3437/?pay_for_order=true&key=wc_order_569cda450dc6a.
This change in url breaks the woocommerce functionality (ie the order in question does not load).
How can I change all instances on & in urls on my site to & using the .htaccess file?
Thanks.
Please try:
RewriteCond %{QUERY_STRING} ^(.*)&(.*)$
RewriteRule ^(.*)$ /$1?%1&%2 [L,R=301]
Related
I am trying to redirect any page on a site that contains a p=item parameter at any point in the url to a specific url on a different domain.
I've tried to piece it together from various instruction on how to do it via htaccess but to no avail.
Try:
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)p=item(&|$)
RewriteRule ^ http://different-domain/url? [L,R]
I have a website which is currently developed using Drupal.
I want to use a custom URL redirect using htaccess for multilingual website.
At the moment the original url is: http://mydomain.com/page-title/?lang=en
What I want to use is something like this http://en.mydomain.com/page-title
How should I do that?
Thank you.
Try this:
RewriteCond %{HTTP_HOST} ^(en).(mydomain.com)$
RewriteCond %{QUERY_STRING} !lang=
RewriteRule ^(.*)$ /$1?lang=%1 [L,QSA]
So when access http://en.mydomain.com/page-title, it will rewrite to /page-title?lang=en
On my website for SEO purpose the link to hotel.php?hotel_id=104 is changed to parkgrand.html
and changed htaccess to refer to the same script
code : RewriteRule ^parkgrand\.html$ /hotel.php?hotel_id=104
Till this it works fine. But I want if some user still accesses the old url i.e. hotel.php?hotel_id=104 then he should get automatically redirected to parkgrand.html and user agent should get a response 301
So, the code now becomes
RewriteCond %{REQUEST_URI} ^/hotel.php
RewriteCond %{QUERY_STRING} ^hotel_id=104
RewriteRule ^hotel.php /parkgrand.html [L,R=301]
RewriteRule ^parkgrand\.html$ /hotel.php?hotel_id=104
But this is causing a redirect loop and the intended page doesn't gets displayed to the user.
Can anyone tell me what should be the correct code for this.
Give this a try:
# Redirect /hotel.php?hotel_id=104 to /parkgrand.html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+hotel\.php\?hotel_id=104[&\s] [NC]
RewriteRule ^ /parkgrand.html? [R=302,L]
Change from R=302 to R=301 once you confirm it is working to avoid caching.
Keep in mind you may have been cached from your previous attempts since you're using R=301, I will recommend you to test the above using a different browser to make sure its working in case your usual browser is cached.
I have written a rewrite rule in the .htaccess file for my website page:
RewriteRule ^nice_url/$ ?p_action=user_profile&post_author=45 [L]
The full link is: "http://www.example.co.il/nice_url/" it works perfect.
BUT, when I try to create a sitemap (e.g. with http://www.web-site-map.com/), I have an indication that the link "http://www.example.co.il/nice_url/" is broken.
Why?
The link is working fine. Why is it indicated as broken?
Thanks!
You can just add another rule to externally redirect long URL to nice URL like this:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+\?p_action=user_profile&post_author=45\s [NC]
RewriteRule ^ nice_url? [R=301,L]
UPDATE: Alright I checked that sitemap generator is putting & instead of & in generated URLs.
You need to add this additional rule to handle this:
# convert & to &
RewriteCond %{QUERY_STRING} ^(.*)&(.*)$ [NC]
RewriteRule ^ %{REQUEST_URI}?%1&%2 [L,R,NE]
Seems that I found the problem:
I have a main .htaccess file that redirects to 3 different folders. Each folder is for a different website (all in the same host).
One of the websites is in WP. The rewrite happens well.
BUT, when I try to generate a sitemap - the wp returns a 404 for the sitemap generator and thats why I get an error.
solution: I'll probably try to rewrite from the php and not from the htaccess.
On my current website I use parameters in querystrings to select the content shown to the user (e.g. www.domain.tld/index.php?site=linklist&page=2). I want to switch to wordpress and have all old links redirected to the new permalinks of wordpress.
When having site=linklist in the query string the user should be redirected to www.domain.tld/my-new-linklist . If the querystring contains site=about the user should be redirected to www.domain.tld/about-me ,...
How can I realize this using htaccess?
In the htaccess file in your document root, try adding these above any of your wordpress rules:
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|.*)site=linklist&?($|.*)
RewriteRule ^/?index.php$ /my-new-linklist?%1%2 [L,R=301]
RewriteCond %{QUERY_STRING} (^|.*)site=about&?($|.*)
RewriteRule ^/?index.php$ /about-me?%1%2 [L,R=301]
etc.
Any other query string gets passed along, but the site=something is stripped out.