htacces URL rewrite redirection - .htaccess

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]

Related

.htaccess URL redirect for sub domain and query pattern

I need to redirect via .htaccess such an URL:
mydomain.com/?c=*
into
sub.mydomain.com/?c=*
For example:
must be redirected
mydomain.com/?c=123&a=1&b=2
into
sub.mydomain.com/?c=123&a=1&b=2
must not be redirected neither
mydomain.com/folder/?c=123&a=1&b=2
nor
mydomain.com/?cb=123&a=1&b=2
My Apache ver 2.4.29.
Thank you.
You can use the following rule
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^c=.*$ [NC]
RewriteRule ^$ http://sub.domain.com/ [L,R]

Redirect a page in htsccess

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]

Redirect URL alternatives with htaccess

I am able to redirect URL to another URL with htaccess by using the following directive:
RewriteCond %{REQUEST_URI} ^/example$
RewriteRule (.*) /pages/example [L,R=301]
RewriteCond %{REQUEST_URI} ^/example
RewriteRule (.*) /pages/example [L,R=301]
But I want to make this with a single directive in htaccess and this directive should cover all alternatives;
http://mydomain.com/example -> http://mydomain.com/pages/example
http://mydomain.com/example/ -> http://mydomain.com/pages/example
http://mydomain.com/example/test -> http://mydomain.com/pages/example/test
How can I do this with a single .htaccess? Any thoughts?
Thanks for your help.
Try this :
RewriteRule ^example(/(test)?)?$ /pages/example$1 [L,R=301]

Redirect by .htaccess doesn't work

I want the URL www.michelenerna.nl to be redirected to www.michelenerna.nl/wycliffe.
The actual Joomla path is /wycliffe =
http://www.michelenerna.nl/index.php?option=com_content&view=article&id=97&Itemid=249
So, I thought: the following lines in .htaccess should be appropriate, but it doesn't work. www.michelenerna.nl still directs to www.michelenerna.nl
This is the code:
Options SymlinksIfOwnerMatch
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.michelenerna.nl [NC]
RewriteRule ^article(.*)$ http://www.michelenerna.nl/index.php?option=com_content&view=article&id=97&Itemid=249/$1 [R=301,L]
Why doesn't it work?
Try using the following instead:
RewriteCond %{HTTP_HOST} ^(www.)?michelenerna.nl$ [NC]
RewriteRule ^(/)?$ wycliffe/index.php [L]
You can also achieve this in the your server cPanel by going to the "Redirect" page and selecting the options that apply to you.
The following works for me:
RewriteCond %{HTTP_HOST} ^(www.)?michelenerna.nl$
RewriteRule ^(/)?$ wycliffe [L]

htaccess redirection help needed

I have a dynamic url domain.com/product/Paper_Bags/Merchandise_Bags_-_Matte_Colors/6_25__X_9_25_/Misty_Grey?7. Which when called need to redirect to domain.com/paper-merchandise-bags-plain-white/
I am using the condition and the rule as
RewriteCond %{QUERY_STRING} (.*)$
RewriteRule ^(.*)/Misty_Grey http://domain.com/paper-merchandise-bags-plain-white/? [R=301,L]
But its not working. Can Someone help me to solve this issue.
If i use RedirectMatch ^(.*)/Misty_Grey http://domain.com/paper-merchandise-bags-plain-white/
Its getting redirected to http://domain.com/paper-merchandise-bags-plain-white/?7
Is there any way to remove the ?7 so tha the querystring will not be visible
Try the following commands,
//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com[nc]
RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
//301 Redirect Old File
Redirect 301 http://domain.com/product/Paper_Bags/Merchandise_Bags_-_Matte_Colors/6_25__X_9_25_/Misty_Grey?7 http://domain.com/paper-merchandise-bags-plain-white/?

Resources