nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

redirect to www in lighttpd

This is a discussion on redirect to www in lighttpd within the Web servers forums, part of the Mastering Servers category; I tried this on my lighttpd.conf as stated in the tutorial but I can still access the mydomain.com (no www) ...


Go Back   nixCraft Linux Forum > Mastering Servers > Web servers

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 03-25-2007, 07:17 AM
Junior Member
User
 
Join Date: Mar 2007
Posts: 13
Rep Power: 0
muks
Default redirect to www in lighttpd

I tried this on my lighttpd.conf as stated in the tutorial but I can still access the mydomain.com (no www) URL

Code:
$HTTP["host"] == "^mydomain\.com$" {
server.document-root = "/home/mydomain/www"
server.errorlog = "/var/log/lighttpd/mydomain.com/error.log"
accesslog.filename = "/var/log/lighttpd/mydomain.com/access.log"
url.redirect = ( "^/(.*)" => "http://www.mydomain.com/$1" )
}
and both www and no-www redirects me now to the server.document-root of the whole server ("/var/www/html/") and not "/home/mydomain/www"

I've also activated the mod_redirect module

any ideas?
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-27-2007, 09:36 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Any distro with shell
Posts: 910
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Replace
Code:
url.redirect = ( "^/(.*)" => "http://www.mydomain.com/$1" )
With
Code:
 $HTTP["host"] =~ "^www\.(.*)" {   url.redirect = ( "^/(.*)" => "http://%1/$1" ) }
SO if use types url www.cricketnow.in she will go to http://cricketnow.in/
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
  #3 (permalink)  
Old 03-27-2007, 09:39 AM
Junior Member
User
 
Join Date: Mar 2007
Posts: 13
Rep Power: 0
muks
Default

thanks for the reply

but I want the other way around

I want users who type http://cricketnow.in/ will be redirected to http://www.cricketnow.in/

Reply With Quote
  #4 (permalink)  
Old 03-27-2007, 09:55 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Any distro with shell
Posts: 910
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

In that case replace
Code:
url.redirect = ( "^/(.*)" => "http://www.mydomain.com/$1" )
With
Code:
$HTTP["host"] =~ "^domain\.com$" { url.redirect = ( "^/(.*)" => "http://www.domain.com/$1" ) }
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
  #5 (permalink)  
Old 05-31-2007, 07:51 AM
Junior Member
User
 
Join Date: May 2007
My distro: REDHAT EL 5
Posts: 4
Rep Power: 0
iluvhk is on a distinguished road
Default

Hi,

The redirect doesn't work in my wordpress.

when I type domain.com/date/day/post, it redirects me to www.domain.com/index.php/date/day/post, thus it gives me a 404 error. I think this is due to my rewrite rule that I Have.. but I have no idea how to fix it. I am currently running my wordpress on lighttpd.

Here is my rewrite rule:

url.rewrite = (
"^/(wp-.+).*/?" => "$0",
"^/(sitemap.xml)" => "$0",
"^/(xmlrpc.php)" => "$0",
"^/(news-sitemap.php)" => "$0",
"^/(google_adsense_script.htm)" => "$0",
"^(/(images|img|jcap|photo/.*)$" => "$1",
"^/(.+)/?$" => "/index.php/$1"
)

Does anyone know how to fix it? I need to get this done asap, because google is reading doubt post (www.domain.com and domain.com)

Thanks in advance,
Calvin
Reply With Quote
  #6 (permalink)  
Old 05-31-2007, 10:37 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Any distro with shell
Posts: 910
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Hi,

For domain.com/index.php/slug/.. you don't need url.rewrite it is done by WP itself. If you need domain.com/slug/ (w/o index.php) you need mod_rewrite. Here is what I use for my own blog:
For wp seo clean urls:
Code:
server.error-handler-404 = "/index.php?error=404"
To redirect cyberciti.biz/urls/... to www.cyberciti.biz/url use as follows (replace it with your own domain name)

Code:
$HTTP["host"] =~ "^cyberciti\.biz$" { url.redirect = ( "^/(.*)" => "http://www.cyberciti.biz/$1" ) }
Let me know if you need any help
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
  #7 (permalink)  
Old 05-31-2007, 08:12 PM
Junior Member
User
 
Join Date: May 2007
My distro: REDHAT EL 5
Posts: 4
Rep Power: 0
iluvhk is on a distinguished road
Default

hmm.. doesn't seem like it is working..

the redirect works if it was just simply domain.com.

But when I try to go to domain.com/slug/post. it redirects me to www.domain.com/index.php/slug/post, which doesn't exist, but www.domain.com/slug/post works. soo same problem still..

Calvin
Reply With Quote
  #8 (permalink)  
Old 05-31-2007, 09:07 PM
rockdalinux's Avatar
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 557
Rep Power: 6
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
Default

U need only 2 lines as pointed out by vivek, remove your rest of the junk (your mod_rewrite seo code) , here is code from one my own domain:
Code:
server.document-root = "/home/lighttpd/domain.com/http"
accesslog.filename         = "/var/log/lighttpd/domain.com/access.log"

  # WP seo urls
  server.error-handler-404 = "/index.php?error=404"
 
  # feedburner redirect
  $HTTP["useragent"] !~ "FeedBurner" {
   url.redirect = (
         "^/feed*" => "http://feeds.feedburner.com/myUrl",
         "^/\?feed=*" => "http://feeds.feedburner.com/myUrl"
   )
  }
 # redirect all  domain.com/2005/01/url/ to www.domain.com/2005/01/url/ 
 # send 301
 $HTTP["host"] =~ "^domain\.com$" { url.redirect = ( "^/(.*)" => "http://www.domain.com/$1" ) }
So remove your junk code add as above also make change to wp by visiting yourblog.com/wp-admin/ > Options > permalink > Type new slug in "Custom structure" (e.g. /%category%/%postname%/ ) > Save changes and restart lighttpd. It should work now.
__________________
Rocky Jr.
You may have my body & soul, but you will never touch my pride!

If you have knowledge, let others light their candles at it.

Certified to work on HP-UX / Sun Solaris / RedHat
Reply With Quote
  #9 (permalink)  
Old 05-31-2007, 10:22 PM
Junior Member
User
 
Join Date: May 2007
My distro: REDHAT EL 5
Posts: 4
Rep Power: 0
iluvhk is on a distinguished road
Default

It works now Thank you very much guys.

I really appreciated it.

Calvin
Reply With Quote
  #10 (permalink)  
Old 06-01-2007, 12:17 AM
Member
User
 
Join Date: Jun 2005
Posts: 78
Rep Power: 0
jerry
Default

Quote:
Originally Posted by iluvhk View Post
It works now Thank you very much guys.

I really appreciated it.

Calvin

On a related note you can use google site ( http://www.google.com/webmasters/sitemaps/ ) to force to use www.domain.com or domain.com only while indexing your blog. You can set your preferred domain in google sitemaps. Chk this out: Webmaster Help Center - What's a preferred domain?

Can you show us your blog url (if you don't have any problem) ?

Babai
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Apache Redirect / to index.php using mod_rewrite .htaccess kasimani Web servers 1 04-18-2008 11:17 PM
Apache and lighttpd together anjanesh Web servers 4 08-29-2007 05:11 PM
Redirect + Rewrite Problem in Lighttpd Lizard King Web servers 4 07-17-2007 09:44 AM
How to redirect Output puppen Shell scripting 15 12-06-2006 08:44 PM
How can I redirect the output of time command to file warren Linux software 13 08-25-2006 11:17 AM


All times are GMT +5.5. The time now is 05:19 AM.


Powered by vBulletin® Version 3.7.2 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36