Remove the %2F from query string using htaccess - .htaccess

How do you remove the %2F from the query string in the rewritten URL below?
This is my HTACCESS file...
RewriteCond %{HTTP_HOST} ^test\.example\.com$ [NC]
RewriteRule ^ http://www.example.com/?retailcentre=test$1%{REQUEST_URI} [QSA,NE,R=301,L]
Referral URL...
http://test.example.com/?utm_source=email&utm_medium=email&utm_campaign=022641ReservedEventCustomerEmail
above then redirects to this REWRITTEN URL...
http://www.example.com/?retailcentre=test%2F&utm_source=email&utm_medium=email&utm_campaign=022641ReservedEventCustomerEmail
as you can see it adds a %2F after the retailcentre=test which needs removing.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^test\.example\.com$ [NC]
RewriteRule ^ http://www.example.com%{REQUEST_URI}retailcentre=test [QSA,NE,R=301,L]

Related

How to Rewrite URL in htaccess

I have URLs with two query parameters e.g. /skills/keywords/list.php?industry=retail&q=analyst and I'd like to redirect those URLs to /list-of-%2-skills-in-%1 .
I have tried the code below which looks at the query "industry" and "q" to build the destination URL: /list-of-%2-skills-in-%1
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^industry=(.*)&q=(.*)$ [NC]
RewriteRule ^skills/keywords/list\.php$ /list-of-%2-skills-in-%1? [L,R=301]
I'm expecting: /skills/keywords/list.php?industry=retail&q=analyst to redirect to /list-of-analyst-skills-in-retail which it does but I have a 404 content not found.
Can someone point me to the right direction please?
This is because the destination path /list-of-%2-skills-in-%1 doesn't exist on your server. You need to rewrite this path to the existent file /skills/keywords/list.php?industry=retail&q=analyst .
RewriteEngine On
RewriteBase /
#redirect /skills/keywords/list.php?industry=foo&q=bar
#to /list-of-bar-skills-in-foo
RewriteCond %{THE_REQUEST} /skills/keywords/list\.php\?industry=([^&]*)&q=([^\s]+) [NC]
RewriteRule ^skills/keywords/list\.php$ /list-of-%2-skills-in-%1? [L,R=301]
#rewrite new URL to the old one
RewriteRule ^list-of-([^-]+)-skills-in-([^-]+)/?$ /skills/keywords/list.php?industry=$1&q=$2 [NC,L]

Redirect entire domain with its corresponding URL and query string except one

I have a rule in my .htaccess that redirects an entire domain with its URL and query string to a new domain. However I want to exclude one URL from this. I want to still redirect that URL for strip out the query string from that. So for eg https://www.test1.com/search?type=content should be redirected to https://www.test.com/search stripping out the query string but for the rest of the URL the below is fine.
# Redirect users from test1.com to https://www.test.com
RewriteCond %{HTTP_HOST} ^(www.)test1\.com$ [NC]
RewriteRule ^ https://www.test.com%{REQUEST_URI} [R=301,L]
You can use this :
#redirect and discard querystring from /search?type=content
RewriteCond ℅{THE_REQUEST} /search/?\?type=content [NC]
RewriteRule ^ https://www.test.com%{REQUEST_URI}? [R=301,L]
# Redirect users from test1.com to https://www.test.com
RewriteCond %{HTTP_HOST} ^(www.)test1\.com$ [NC]
RewriteRule ^ https://www.test.com%{REQUEST_URI} [R=301,L]

Rewrite rule 301 htaccess

Via .htaccess, I would like to create an automatic 301 from an old URL to a new url:
An example old url is: http://www.example.com/test.html?s=2&ss=3
I would like that to be automatically redirected to: http://www.example.com/test.html
If you want to match this specific URL and query parameters then you can use this rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^s=2&ss=3^ [NC]
RewriteRule ^test\.html$ %{REQUEST_URI}? [L,R=302]
If you want to use this query string with any URI then use:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^s=2&ss=3^ [NC]
RewriteRule ^ %{REQUEST_URI}? [L,R=302]
? after %{REQUEST_URI} is needed to strip off any query string.

.htaccess URL redirection appending query string with target URL

I am new to .htaccess redirect.
I have a source URL with too many parameters query string.
Source
http://localhost/se/karriar/?utm_source=A_candy_box&utm_medium=Printed_media&
utm_term=2013&utm_content=Want_a_fresh_start_to_your_career%3F&
utm_campaign=Mint_pastille_campaign
Target: http://www.sample-website.com
When I tried to call source URL its getting redirected along with query string as like below.
http://www.sample-website.com?utm_source=A_candy_box&utm_medium=Printed_media&
utm_term=2013&utm_content=Want_a_fresh_start_to_your_career%3F&
utm_campaign=Mint_pastille_campaign
I have written the below script in .htaccess file.
RewriteCond %{HTTP_HOST} ^(www.)?localhost$ [NC]
RewriteCond %{QUERY_STRING} ^utm_source=A_candy_box&utm_medium=Printed_media&utm_term=2013&utm_content=Want_a_fresh_start_to_your_career%3F&utm_campaign=Mint_pastille_campaign$ [NC]
RewriteRule ^se/karriar(.*)$ http://www.sample-website.com [R=301,L,NC] `
I would like to not appending query strings in the targeted URL. Can you any one help me?
Replace your .htaccess with this
RewriteCond %{HTTP_HOST} ^(www.)?localhost$ [NC]
RewriteCond %{QUERY_STRING} ^utm_source=A_candy_box&utm_medium=Printed_media&utm_term=2013&utm_content=Want_a_fresh_start_to_your_career%3F&utm_campaign=Mint_pastille_campaign$ [NC]
RewriteRule ^se/karriar(.*)$ http://www.sample-website.com? [R=301,L,NC]
Append ? after your target domain.

Rewrite Conditions in htaccess file

RewriteCond %{HTTP_HOST} ^mysite.com$
RewriteCond %{REQUEST_URI} ^/ex-ex[/]*
RewriteRule ^(.*)$ /subsite/ex [R=permanent,L,NE]
I am redirecting mysite.com/ex-ex to mysite.com/subsite/ex
This is working fine, but mysite.com/ex-ex/page1 redirects to mysite.com/subsite/ex. How can I redirect to mysite.com/subsite/ex/page1?
How can I append the remaining part of url also to new url pattern?
This would do it:
RewriteCond %{HTTP_HOST} ^mysite.com$
RewriteRule ^/ex-ex(.*)$ /subsite/ex$1 [R=permanent,L,NE]
Edit: added a slash in the Rule

Resources