Redirect a page in htsccess - .htaccess

I want to redirect
m.sample.com/?articulo=something
to
http://www.sample.com/camisetas/something.html

Try this code :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^m.sample.com$
RewriteRule ^\?articulo=(.*)$ http://www.sample.com/camisetas/$1.html [R=301]

Related

Redirect after a RedirectRule has taken place to other website

I have a website, let's say www.example.com but this used to be www.example.nl. All traffic from www.example.nl is now redirected to www.example.com, but as we changed some naming conventions, www.example.nl/seeds now has to redirect to www.example.com/nl/flower-seeds.
The .htaccess file I got contains the following code:
RewriteEngine On
RewriteBase
RewriteCond %{HTTP_HOST} !example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L, R=301]
Redirect 301 /seeds/(.*) example.com/nl/flower-seeds/$1
When I navigate to www.example.nl/seeds/ I end up at www.example.com/seeds/ which ends up in a 404 because I'm missing the /nl/flower- part.
I think Redirect doesn't work properly when the URL is already altered by a RewriteRule. How would you tackle this problem? Any help is appreciated!
You should exclude /seeds/ directory form general rules like this :
RewriteEngine On
RewriteCond %{HTTP_HOST} !example.com$ [NC]
RewriteCond %{REQUEST_URI} !/seeds/(.*)
RewriteRule ^(.*)$ http://www.example.com/$1 [L, R=301]
RewriteCond %{HTTP_HOST} !example.com$ [NC]
RewriteRule ^seeds/(.*)$ http://www.example.com/nl/flower-seeds/$1 [L, R=301]
Note: clear browser cache then test
Also , don't use regex with redirect like what you did :
Redirect 301 /seeds/(.*) example.com/nl/flower-seeds/$1
Here this (.*) has no meaning , you could use either RedirectMatch or RewriteRule

Advanced htaccess rewrite

i want to redirect all links with this format
https://besthost.tn/aze/viewticket.php?tid=VARIABLE1&c=VARIABLE2
to
https://besthost.tn/client-2/?ccce=viewticket&tid=VARIABLE1&c=VARIABLE2
the VARIABLE1 and VARIABLE2 must be inchanged while the redirection.
thank you
Try :
RewriteEngine on
RewriteCond %{THE_REQUEST} /viewticket.php\?tid=([^&]+)&c=([^\s&]+) [NC]
RewriteRule ^ /client-2/?ccce=viewticket&tid=%1&c=%2 [NC,L,R]
This will work from the root and identify '/aze/viewticket.php' and then the tid=X&C=X pattern for redirection:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/aze/viewticket\.php [NC]
RewriteCond %{QUERY_STRING} ^tid=(.+)&c=(.+)
RewriteRule ^(.*)$ /client-2/?ccce=viewticket&tid=%1&c=%2 [L,R=301]
The R=301 part indicates a 301 'permanent' redirect which will be cached by the browser and is required if this is a permanent change in your website (for performance reasons).

htacces URL rewrite redirection

I have a link: http://testsite.com/api/v2/1
I would like to point my browser to: 1.testsite.com and using redirection in .htaccess link it to this place: http://testsite.com/api/v2/1
How can I do this?
Try this :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.testsite\.com$ [NC]
RewriteRule ^$ http://testsite.com/api/v2/%1 [L]

htaccess redirect url with domain as variable to an external site

I want to redirect
http://example.com/report?domain=dollarshaveclub.com
to
http://www.semrush.com/info/dollarshaveclub.com+%28by+organic%29
I've tried:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^?domain=$
RewriteRule ^report$ http://www.semrush.com/info/$1+%28by+organic%29 [R=301,L]
But I'm not getting anywhere...What could I try next?
You must remove the R=301, part.
This works for me:
RewriteEngine On
RewriteRule ^report$ http://www.semrush.com/info/$1+%28by+organic%29 [NC]
Found the solution finally:
RewriteCond %{QUERY_STRING} ^domain=(.*)
RewriteRule ^report(.*) http://www.semrush.com/info/%1+(by+organic)? [R=301,L]

.htaccess 301 redirect to the same page with no query string

I want to create a condition that if page has parameter in URL like ?print=1 - redirect this page to itself without any querystring.
Example:
I want this page:
http://sos-med.com/en/specific_page.html?print=1&ok=1
tp redirect (301) to the same URL with no Query string:
http://sos-med.com/en/specific_page.html
My code is:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^*print=*$ [NC]
RewriteRule ^(.*)$ %{REQUEST_URI}?
I have no test server, so can you tell me if my code is ok?
The code above is for every page on website. And before implementing that rule I would like to try the redirect for one specific page (see my example).
How to modify the code to work with "specific_page.html" only?
I want only .htaccess solution, not PHP code.
You're close, your %{QUERY_STRING} regex isn't right, and you're missing the 301 redirect flag:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^print=.*$ [NC]
RewriteRule ^(.*)$ %{REQUEST_URI}? [L,R=301]
Try that.
Thanks, and If I want to redirect single specific page: sos-med.com/en/aaa.html?print=1&ok=1 to sos-med.com/en/aaa.html ? –
Then you'd change what the rule matches against:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^print=.*$ [NC]
RewriteRule ^en/aaa.html$ %{REQUEST_URI}? [L,R=301]
Try this one instead :
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*&)?print= [NC]
RewriteRule ^(.*)$ /$1? [L,R=301]

Resources