I'am using a mod_rewrite to get the virtual subdomain as a variable in my site
and would like to add a rule to hide the index.php and all the variables in the url
but can't get it to work. Any suggestions please?
This is my actual .htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$
RewriteCond %{HTTP_HOST} ^(.*)\.mysite\.com$
RewriteRule ^$ /index.php?member=%1 [P,L]
Your best bet is probably to send in a support ticket and have the domain wildcarded.
.htaccess seems perfect.
Detail Description:
You will need to ask hosting company to add "wild-card" DNS set up to forward all subdomains to Web root directory. For example *.domain.com to www.domain.com. They can do this by adding A entry in DNS setting
HTACCESS Code
<IfModule mod_rewrite.c>
# Redirect to user blog (with any trailing path)
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9]).example.com(.*)$ [NC]
RewriteRule ^(.*)$ /index.php?member=$1 [R=301,L]
## Otherwise, force www;
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/ [R=301,L]
</IfModule>
Related
I need to redirect all sites that as a specific word to one site.
I try to explain myself better.
I have a domain, it's example name is example.com
What I need is when an user digit:
something.example.com
or
anothertext.example.com
or
blablabla.example.com
and many others it will be redirect to example.com
I found this code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule ^(.*)$ https://www.example.com [R=301,L]
But it redirect all my domains in that server.
I discover it because I create a new virtual host, with a new domain but I can't see it on the web because it automatically redirects on example.com
So, I thought that maybe if I specify the word: "example" I can solve the problem.
Sorry for my bad english.
Thanks for help.
Luca.
Check one of rules that you more prefer:
<IfModule mod_rewrite.c>
RewriteEngine on
# something.example.com/any to https://example.com/
RewriteCond %{HTTP_HOST} ^something\. [NC]
RewriteRule (.*) https://example.com/ [R=301,L]
# something.example.com/any to https://example.com/any
RewriteCond %{HTTP_HOST} ^something\. [NC]
RewriteRule (.*) https://example.com/$1 [R=301,L]
# something.example.com/any to https://example.com/, full subdomain with and without www
RewriteCond %{HTTP_HOST} ^(www\.)?something\.example\.com [NC]
RewriteRule (.*) https://example.com/ [R=301,L]
# something.example.com/any to https://example.com/any, full subdomain with and without www
RewriteCond %{HTTP_HOST} ^(www\.)?something\.example\.com [NC]
RewriteRule (.*) https://example.com/$1 [R=301,L]
</IfModule>
Where my site is hosted, I'm using .htaccess and it has a condition to remove the www and direct to the main page without the www.
<ifModule mod_rewrite.c>
Header set X-Frame-Options DENY
RewriteEngine On
# Required to allow direct-linking of pages so they can be processed by Angular
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule (.*) http://meusite.com.br [R=301,L]
</ifModule>
The problem is this, when someone accesses an internal page with www, it falls for this check and is directed to the home, example:
If someone accesses the link: http://www.meusite.com.br/conteudo/94-vai-criar-um-site-to-your-employee-said-you-can-noble
It will direct to http://meusite.com under the condition.
What I need, is that it is directed to the following link: http://meusite.com/content/94-vai-create-a-site-to-your-employee-behavior-which-cannot-can- -fine only by removing the www from the link.
Does anyone know if this check is possible in .htaccess?
EDIT:
.htaccess is not able to translate your titles from portugese to english.
You should do redirection to normal domain with full link, and then do internal redirection with your backend (i.e. php, ruby) to proper translated link.
Use following code before your redirection, so links with conteudo will be catched here and redirected properly using backreferences:
RewriteCond %{HTTP_HOST} ^www\..* [NC]
RewriteRule ^\/conteudo\/(.*)$ http://menusite.com.br/content/$1 [R=301,L]
Soluction:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
I want to edit the .htaccess file to create an unmasked wildcard redirect of all subdomains to the main www subdomain.
i.e. *.domain.com => www.domain.com
e.g. www.example.domain.com => www.domain.com
When the person types in www.example.domain.com in the browser address bar, I want it to redirect unmasked so that the URL actually visibly changes to www.domain.com.
My present .htaccess file (shown below) forces the 'www' for all 'without www' traffic, i.e. http://domain.com becomes http://www.domain.com, but can't figure out what RewriteCond etc. commands to use for the above requirement.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^(.*)$ "http\:\/\/www\.domain\.com\/$1" [R=301,L]
Any help would be greatly appreciated! Thanks in advance.
Have your .htaccess like this:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
It is simple, try :
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,QSA,R=301]
You won't need your rule that adds the www also, so just remove it.
I am using Codeigniter-.
My domain currently does not redirect to www version.
For example if I type mydomain.com then it stays mydomain.com. I want to redirect it to www.mydomain.com.
If someone types mydomain.com/controller/method then it should be www.mydomain.com/controller/method.
Another problem: I already tried other solutions but the problem is when it redirects to www version, it automatically adds "index.php" in the URL. But when I type www in the domain name then it works fine, no "index.php" in the URL. This problem occurs only during the redirection.
Here is my .htaccess file (I've removed the redirection code)
RewriteCond $1 !^(index\.php|system|rpc_relay.html|canvas.html|robots\.txt)
RewriteCond $1 !^(sitemap\.xml|export)
RewriteRule ^(.*)$ /index.php/$1 [L]
Any help would be greatly appreciated.
To redirect from http:// to http://www. , and also remove the route file (index.php) in the url, put these lines on your htaccess :
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
RewriteCond $1 !^(index\.php|images|css|js|styles|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
the domain is :
domain.com
folder with direct access :
images|css|js|styles
hope this help
I've used the following before:
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteCond %{HTTP_HOST} (.+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
</IfModule>
To redirect domain.com to www.domain.com, you could use the following rewrite rule. Please replace domain.com with your own domain name.
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
I don't know why there are such complex RewriteRules answers, even though Gobhi has provided a nice generic solution (= whatever the domain name is, it works).
Here's my solution.
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
RewriteRule (.*)/index\.php$ $1/ [QSA]
</IfModule>
I would like to modify my .htaccess file so that when someone comes into my site without typing www the site always redirects them to the www version. For example, if my url is www.abc.com and they just type abc.com, I want to redirect them to abc.com.
Here is my current htaccess file:
<IfModule mod_rewrite.c>
RewriteBase /
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Normally I know how to do the redirect, but im having issues since it already has those few lines in there.
I use the code below. It can be used for any domain name. You just need to enter it in your .htaccess file.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
(edited to have all the code in the same block)
Add something like this immediately after RewriteEngine on:
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*) http://www.example.com/$1 [R=301]
There are two methods available
1) use mod_alias apache module
Redirect permanent /something http://yourwebsite.com/something
2) Add the following entry in your .htaccess / http.conf / yourwebsite.conf in the webserver configuarion directory
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourwebsite.com
RewriteRule ^(.*)$ http://www.yourwebsite.com$1 [R=permanent,L]
If you want redirect example.com to www.example.com you can try below code
RewriteEngine on
RewriteCond %{HTTP_HOST} !www.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]