Subdomain URL Redirect dynamically. .htaccess - php

I want redirect url using .htaccess
like.
abc.website.com to website.com/folder/abc
http://abc.website.com to http://www.website.com/folder/abc
using .htaccess from PHP server

Use below rule,
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www|webmail|help|whm|root)
RewriteCond %{HTTP_HOST} ^(.+?)\.website.com
RewriteRule ^ http://www.website.com/folder/%1 [R=301,L]

Try putting this in your .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^abc.website.com
RewriteRule ^(.*)$ http://website.com/folder/abc/$1 [L,NC,QSA]
For a more general rule (that works with any subdomain, not just sub) replace the last two lines with this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.abc.website\.com
RewriteRule ^(.*)$ http://website.com/folder/%1/$1 [L,NC,QSA]
I hope it will work for you.

Related

How to hide a part of the url using htaccess file

I have the following Rewrite rules in my .htaccess file.
RewriteEngine On
RewriteCond %{HTTPS} !=off
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^([0-9]+)/([a-zA-Z0-9_-]+)$ system.php?id=$1&title=$2 [L]
With this rules I am getting the url as follows.
http://www.example.com/1111/article-title
I want to hide the "1111" from the url while passing that to the system.php as an argument.Also I need to add some text instead of "1111". So my url should be as follows.
http://www.example.com/text-article-title
Is there any way to do this? Please give some insight on this.
Thanks.
Try this
RewriteCond %{REQUEST_URI} !^example.com/1111/article-title [NC]
RewriteRule ^example.com/(.*)$ example.com/text-article-title/$1 [L]
that should do the trick.

redirect folder subdomain to subdomain.domain.com in htaccess

I have a domain name domain.com and some folders inside it. When i am accessing the folders inside this domain i can access the folder like this.
http://www.domain.com/folder
I want to convert this url with htaccess to
http://www.folder.domain.com
I would like to have similar urls for all folders so its a wildcard entry.
Please tell me how can it be done with htaccess.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule ^(.*)$ http://subdomains.domain.com/$1 [L,NC,QSA]
You can use:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:www\.)?domain\.com [NC]
RewriteRule ^([^/]+)(/.*)?$ http://www.$1.domain.com$2 [R=301,L,NC]
RewriteCond %{HTTP_HOST} ^www\.(.+)\.domain\.com [NC]
RewriteRule ^(.*)$ /%1/$1 [L]
To redirect requests to www.example.com/blog to blog.example.com, try this :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^blog/(.*)$ http://blog.example.com/$1 [L,QSA,R=301]
RewriteCond %{HTTP_HOST} ^blog\.example\.com$
RewriteCond %{REQUEST_URI} !^blog/
RewriteRule ^(.*)$ /blog/$1 [L,QSA]
For other you have to set dynamic name and pass as parameter, for simple blog you can take help of this question.

replacing Login URL to short URL with .htaccess

I have an URL as :
http://mydomain.com/site/?cmd=home
I want to change the above address to http://mydomain.com/home
i am using .htaccess file like this:
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ /site?cmd=$1 [L]
I am not sure where is the problem?
Thanks in advance
The Rule works the other way around: you want to get from /site/?cmd=home to /home, but with your RewriteRule you are redirecting to /site?cmd= (Probably there is a mistake somewhere?)
If you want to redirect from /site/?cmd=home to /home, like the question states, use the following:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/site
RewriteCond %{QUERY_STRING} ^cmd=(.*)$
RewriteRule ^(.*)$ /%1/? [R=302,L]
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} /site\?cmd=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
# internal forward from pretty URL to actual one
RewriteRule ^([^/.]+)/?$ /site?cmd=$1 [L]

Virtual subdomain using htacess, Pages rewrite rules

I have make virtual subdomain in my code.like below
RewriteCond %{HTTP_HOST} ^(.*)\.mysitename\.com
RewriteRule ^(.*)$ agent.php?asitename=%1 [L,NC,QSA]
it works fine, but it did not work for pages like
RewriteCond %{HTTP_HOST} ^(.*)\.mysitename\.com
RewriteRule ^(.*)/ag_buy.html ag_buy.php?sitename=%1&page=buy [L,NC,QSA]
it redirect all pages top agent.php, but it should only redirect home page to agent.php, for other pages it should work like ag_buy.html to ag_buy.php
and so on.........
please guide me on htaccess how can i make this possible.
The ^(.*)$ matches everything, if you only want the home page, then change it to ^$:
RewriteCond %{HTTP_HOST} ^(.*)\.mysitename\.com
RewriteRule ^$ agent.php?asitename=%1 [L,NC,QSA]
Try to replace the first rule with following code:
RewriteCond %{HTTP_HOST} ^(.).mysitename.com
RewriteCond %{REQUEST_URI} =/
RewriteRule ^(.)$ agent.php?asitename=%1 [L,NC,QSA]

Htaccess giving me too many redirects

I need help modifying my htaccess file. I have:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^phpbb3.*$ http://mydomain.com/phpbb3/ [R=301,L]
RewriteCond %{HTTP_HOST} mydomain.com$
RewriteCond %{REQUEST_URI} !^/wordit
RewriteRule ^(.*)$ http://www.mydomain.com/wordit/$1 [R=302,L]
Originally I only had:
RewriteCond %{HTTP_HOST} mydomain.com$
RewriteCond %{REQUEST_URI} !^/wordit
RewriteRule ^(.*)$ http://www.mydomain.com/wordit/$1 [R=302,L]
Which I need to keep. But I'm not sure how to incorporate the new rule:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^phpbb3.*$ http://mydomain.com/phpbb3/ [R=301,L]
How do I need to format my redirect?
I think this is what is happening: The rewritten URL coming out of your new rule actually matches the rule itself, so it just loops and loops and loops.
A very simple modification might work:
RewriteRule ^phpbb3[^/]+$ http://mydomain.com/phpbb3/ [R=301,L]

Categories