View Full Version : .htaccess rules redirects
katie hunter
12-25-2013, 06:12 PM
Hi, I liked to redirect my non www. urls of my homepage to the www. urls
Ex http://nihonomaru.com/ should redirect to http://www.nihonomaru.com/
However, when i applied this rule to the .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
It is working but now on my forum, where i host my images on lightspeed, img1 subdomain, the images aren't appearing because they also get redirected i.e., img1 gets redirected to www.img1
See http://img1.nihonomaru.com/lighttpd/forum/images/medals/1231.gif
How can i apply an exclusion rule so the redirect doesn't not affect sub-domains? Or for only to apply the redirect for the homepage pages only?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/forum/(.*)
RewriteCond %{REQUEST_URI} !^/img1/(.*)
RewriteCond %{REQUEST_URI} !^/cache/(.*)
RewriteCond %{REQUEST_URI} !^/lighttpd/(.*)
RewriteCond %{REQUEST_URI} !^forum\.nihonomaru\.com
RewriteCond %{REQUEST_URI} !^img1\.nihonomaru\.com
RewriteCond %{REQUEST_URI} ^/chan.*
RewriteRule (.*) - [L]
RewriteCond %{REQUEST_URI} "/lighttpd/"
RewriteRule (.*) $1 [L]
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{REQUEST_URI} !^img1\.nihonomaru\.com
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?nihonomaru.com$
RewriteRule ^$ public/ [L]
RewriteCond %{HTTP_HOST} ^(www\.)?nihonomaru.com$
RewriteRule (.*) public/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
vBNinja
12-25-2013, 07:11 PM
Try
RewriteEngine On
RewriteCond %{HTTP_HOST} !^img1\. [NC]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
That will only work for urls that start with "img1", if you have url's that start with a dynamic digit let me know so i can fix it
katie hunter
12-25-2013, 09:07 PM
Hi vBNinja,
I added it to my .htaccess but I see an internal server error message.
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
This is my current entire rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/forum/(.*)
RewriteCond %{REQUEST_URI} !^/cache/(.*)
RewriteCond %{REQUEST_URI} !^forum\.nihonomaru\.com
RewriteCond %{REQUEST_URI} ^/chan.*
RewriteRule (.*) - [L]
RewriteEngine On
RewriteCond %{HTTP_HOST} !^img1\. [NC]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?nihonomaru.com$
RewriteRule ^$ public/ [L]
RewriteCond %{HTTP_HOST} ^(www\.)?nihonomaru.com$
RewriteRule (.*) public/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
final kaoss
12-26-2013, 12:56 AM
Here you go.
### BEGIN CLOUDFLARE REWRITE (domainB.com to www.domainB)
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
### END CLOUDFLARE REWRITE ###################
katie hunter
12-26-2013, 02:06 AM
Here you go.
### BEGIN CLOUDFLARE REWRITE (domainB.com to www.domainB)
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
### END CLOUDFLARE REWRITE ###################
Hi, why identifying it as specifically redirect everything on port 80 to the http URL?
Max Taxable
12-26-2013, 02:19 AM
Side Note: You have a 404 missing or incorrectly named image here:URL: http://forum.nihonomaru.com/images/styles/OrangeTheme/style/headerBG.gif
Host: forum.nihonomaru.com
IP: 141.101.117.217
Location: Cloudflare
Error/Status Code: 404
Client Port: 56304
Start Offset: 1.308 s
Time to First Byte: 39 ms
Content Download: 0 ms
Bytes In (downloaded): 0.6 KB
Bytes Out (uploaded): 0.6 KB
final kaoss
12-26-2013, 02:51 AM
Not too sure if that matters too much but that's what I've come up with after browsing through several tutorials & articles.
Also I realize that this plugin is a vb3 plugin but it still seems to get the job done in vb4 as well (I've used it for a couple of years now).
https://vborg.vbsupport.ru/showthread.php?t=222898
Hi, why identifying it as specifically redirect everything on port 80 to the http URL?
katie hunter
12-26-2013, 04:16 AM
Side Note: You have a 404 missing or incorrectly named image here:URL: http://forum.nihonomaru.com/images/styles/OrangeTheme/style/headerBG.gif
Host: forum.nihonomaru.com
IP: 141.101.117.217
Location: Cloudflare
Error/Status Code: 404
Client Port: 56304
Start Offset: 1.308 s
Time to First Byte: 39 ms
Content Download: 0 ms
Bytes In (downloaded): 0.6 KB
Bytes Out (uploaded): 0.6 KB
It is embed correctly in here http://forum.nihonomaru.com/azskinz/nihonomaru/style/headerBG.gif
I can't seem to find where this url is in the template.
#headerMain {
background: url(azskinz/nihonomaru/style/headerBG.gif) repeat-x scroll left top transparent;
height: 96px;
padding: 0 20px;
position: relative;
}
Not too sure if that matters too much but that's what I've come up with after browsing through several tutorials & articles.
Also I realize that this plugin is a vb3 plugin but it still seems to get the job done in vb4 as well (I've used it for a couple of years now).
https://vborg.vbsupport.ru/showthread.php?t=222898
I prefer if i don't use any weird plugin's for this, usually .htaccess works + this is outdated i mean it works for vb 3.8 not 4.x.
I don't really have an issue with my forum url, it is working perfectly, my issue is for the sub domain img1 which is lightspeed that is hosting my forum images.
final kaoss
12-26-2013, 04:32 AM
Sorry about that, been posting while I'm half awake over here.
Try this solution.
http://stackoverflow.com/questions/15167508/htaccess-force-www-on-everything-but-subdomains-and-remove-trailing-slashes
katie hunter
12-26-2013, 05:04 AM
We can check it tomorrow :) thanks for your help!
I tried it but it didn't work:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/forum/(.*)
RewriteCond %{REQUEST_URI} !^/cache/(.*)
RewriteCond %{REQUEST_URI} !^forum\.nihonomaru\.com
RewriteCond %{REQUEST_URI} ^/chan.*
RewriteRule (.*) - [L]
#Force www.
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^nihonomaru\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?nihonomaru.com$
RewriteRule ^$ public/ [L]
RewriteCond %{HTTP_HOST} ^(www\.)?nihonomaru.com$
RewriteRule (.*) public/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
I also added this part as well and it didn't work, unless i did something wrong
#Remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.+)/$ /$1 [R=301,L]
CAG CheechDogg
12-26-2013, 05:21 AM
Hello katie,
Try this:
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^yourdomain.com$
RewriteRule ^(.*)$ "http\:\/\/www\.yourdomain\.com\/$1" [R=301,L]
katie hunter
12-26-2013, 01:03 PM
Hello katie,
Try this:
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^yourdomain.com$
RewriteRule ^(.*)$ "http\:\/\/www\.yourdomain\.com\/$1" [R=301,L]
Hi, i tried this but it didn't work, it actually made my homepage not displaying by saying "There is a redirect problem"
Max Taxable
12-26-2013, 06:09 PM
It is embed correctly in here http://forum.nihonomaru.com/azskinz/nihonomaru/style/headerBG.gif
I can't seem to find where this url is in the template.IE says it is missing:
http://www.webpagetest.org/result/131226_2J_KQR/1/details/
Item #49
final kaoss
12-26-2013, 07:42 PM
Yep, max is right. I think you simply misunderstood. Upload the file and the 404 file not found error will vanish.
http://forum.nihonomaru.com/images/styles/OrangeTheme/style/headerBG.gif
katie hunter
12-27-2013, 12:56 AM
I will check it :0) any solution to this redirect issue?
The issue is with the sub-domain, i see this happening:
http://img1.nihonomaru.com/forum/images/stickies/news.png it will be redirected to this http://www.img1.nihonomaru.com/lighttpd/forum/images/stickies/news.png
It has the www. url as well as lightttpd folder.
CAG CheechDogg
12-27-2013, 04:09 AM
Hi, i tried this but it didn't work, it actually made my homepage not displaying by saying "There is a redirect problem"
Bummer..that is what i use to redirect my site to www.mysite.com
Sorry katie...I tried ..
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.