Good evening,
I wanted to know if it is possible to redirect a request to my page as http://test.diogo.me to the page with the content -> http://www.diogo.me/pages/test/ (this redirection must be internal... the browser should point to http://test.diogo.me).
I have been reading about .htaccess and I feel that this is the resolution for me.
I have tried with the following code:
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} !^www\.diogo\.me [NC]
RewriteCond %{HTTP_HOST} ([^.]+)\.diogo\.me [NC]
RewriteRule ^(.*)$ /%1/$1 [L]
The output is error 404 file not found :(Am I going in the right track? Sorry about my expressing limitations. Thanks in advance
Just put this code in your .htaccess and remove your existing lines from there:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{HTTP_HOST} ^test\.diogo\.me$ [NC]
RewriteRule ^$ http://www.diogo.me/pages/test/ [L,P]
You were missing the /pages part
RewriteCond %{HTTP_HOST} !^www\.diogo\.me [NC]
RewriteCond %{HTTP_HOST} ([^.]+)\.diogo\.me [NC]
RewriteRule ^(.*)$ /pages/%1/$1 [L]
Assuming the subdomains have the same document-root as the main domain.
Related
I recovered a project but it is not generic at all. I looked a bit what was on .htaccess but it is not obvious. So I ask you, you will probably have the solution!
Currently my .htaccess file is
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.exemple.com$ [NC]
RewriteRule ^(.*)$ http://exemple.com/$1 [R=301,L]
#RewriteCond %{HTTPS} off
#RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteRule folderA/(.+) www/$1
RewriteRule folderB/(.+) www/$1
with copy of index.php files in folderA/index.php and folderB/index.php.
index.php are :
<?php
header("Location: index.php");
?>
I want the http://exemple/folderA/ , http://exemple/folderB/, http://exemple/folderC/ ... to be written and displayed in the browser but redirects to www/index.php
Commonly new folders are added by the old team. I would like to have the same behavior without the folders that multiply.
Can you help me ?
Thx
What I used was something like this:
RewriteCond %{REQUEST_URI} !www/
RewriteCond %{REQUEST_URI} folderA
RewriteRule (.*) /www/index.php [L]
RewriteCond %{REQUEST_URI} !www/
RewriteCond %{REQUEST_URI} folderB
RewriteRule (.*) /www/index.php [L]
This is a quick-n-dirty approach, that I used on a project recently because out glorious admins think that all code would be in the document root :(
Also, I have no idea whether it will work for you, and you probably could collapse those rules into one.
Whenever someone hits
http://www.example/consumer-complaints
it should become
http://example.com/consumer-complaints
The copy&paste .htaccess rules do not seem to work for me.
It removes www when someone hits
> http://www.example/consumer-complaints
but it redirects to only http://example.com
instead of
http://example.com/consumer-complaints
Can someone write an .htaccess rule for me
Thank you
The .htaccess Code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
Conversely, if you'd prefer to use "www" in all of your URLs, you can code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
I have a website and i want to make it always show as www.mysite .com i put that code in .htaccess :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
now the url shows as www but the website is not shown the browser said "This webpage has a redirect loop"
Note: .htcaccess do not have any code but this few lines i wrote
does i did anything wrong or i miss something??? please help
Edit:
before I add the above code the .htaccess had the following code but not direct to www i remove it :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteCond %{QUERY_STRING} ^m=1$
RewriteRule (.*) $1? [R=permanent]
# END WordPress
could that be updated to solve my problem?
if you are doing it at windows server it will not work if it is window you have to create web.config file n for linux it should be .htaccess
Ok so Wordpress is also there. Make sure to do these 2 things:
Put your 301 rule above WP's rules i.e. just below RewriteBase line
Update WP settings to have your site address with www
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
or
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
My .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^deathga.me$ [NC]
RewriteRule ^(.*)$ http://deathga.me/$1 [L,R=301]
</IfModule>
It correctly redirects from www.deathga.me to deathga.me, which solves many things. But it also redirects play.deathga.me to deathga.me/play/ , which is undesirable.
My question is basically the opposite to this: Redirecting http://example.com to http:/www.example.com while keeping http://subdomain.example.com access intact. Only I cannot figure out how to apply it to my site, even looking at that question, googling and trying many things. The question itself is pretty simple: how to redirect www.example.com to example.com but keep sub.example.com in that subdirectory? I am not even sure if it's a problem with Godaddy or with htaccess... where should I start looking into? This is a screenshot of Godaddy subdomain configuration:
EDIT: Full .htaccess now:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^play.deathga.me$ [NC]
RewriteCond %{HTTP_HOST} !^deathga.me$ [NC]
RewriteRule ^(.*)$ http://deathga.me/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^play.deathga.me$ [NC]
RewriteCond %{HTTP_HOST} !^deathga.me$ [NC]
RewriteRule ^(.*)$ http://deathga.me/$1 [L,R=301]
</IfModule>
Apparently what I wanted to do cannot be done with the 'fake' godaddy subdomain and an Economy account: Setting up a "real" subdomain with Go Daddy .
Thank you #borazslo for all the help.
I need to redirect users accessing mysite.com to www.mysite.com in my .htaccess file.
The problem is anything I try won't work, I think because ^mysite.com doesn't exclude www.mysite.com so that will create a bad loop, but I usually get error 500.
I also need to exclude another subdomain, the img.mysite.com.
How can I do that?
I used many examples from the net & a few htaccess generators, which gave me this code:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mywebsite.com[nc]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [r=301,nc]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This is what you need - taken from the default Drupal .htaccess
Try something like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.mywebsite.com$ [NC]
RewriteRule ^/(.)$ http://www.mywebsite.com/$1 [L,R=301]