nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

lighttpd redirect rules!

This is a discussion on lighttpd redirect rules! within the Web servers forums, part of the Mastering Servers category; Hello , I want when user type : website.com > will be redirected to www.website.com/forum www.website.com > will be redirected ...


Go Back   nixCraft Linux Forum > Mastering Servers > Web servers

Linux answers from nixCraft.


Web servers Discussion on Apache, Nginx and Lighttpd HTTP/web server and configuration issues.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-12-2009, 09:53 PM
Junior Member
User
 
Join Date: Jun 2009
OS: Debian
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 0
maxtox is on a distinguished road
Default lighttpd redirect rules!

Hello ,

I want when user type :

website.com > will be redirected to www.website.com/forum
www.website.com > will be redirected tp www.website.com/forum

so i use vbulletin with vbseo mod

Quote:
$HTTP["host"] =~ "(^|\.)website\.com$" {

server.document-root = "/home/website.com/public_html"
#server.errorlog = "/home/lighttpd/website.com/error.log"
#accesslog.filename = "/home/lighttpd/website.com/access.log"



}




#seo
url.rewrite-once = (

"^/forum/(sitemap.*\.(xml|txt)(\.gz)?)$" => "/forum/vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1",
"^(/forum/(admincp|modcp|clientscript|cpstyles|images|custom avatars|styles|smiley)/.*)$" => "$1",
"^(/website\.ico|/robots\.txt|.*clear\.gif)$" => "$1",
"^/forum/(.+)\?(.*)$" => "/forum/vbseo.php?$2",
"^/forum/(.+)$" => "/forum/vbseo.php",

)
Thanks for your help!

Cheers.
Reply With Quote
  #2 (permalink)  
Old 12-12-2009, 06:27 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
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

Add the following to config and reload lighttpd (replace website.com with actual domain name)
Code:
$HTTP["host"] =~ "^website\.com$" { url.redirect = ( "^/(.*)" => "http://www.website.com/$1" ) }
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 12-12-2009, 03:09 PM
Junior Member
User
 
Join Date: Jun 2009
OS: Debian
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 0
maxtox is on a distinguished road
Default

Hi mate ,

It work with adding the www but i got 404 not found with www.website.com


but

website.com > work redirect to > website.com/forum
www.website.com return > 404 not found

i've modified the code by adding ( forum )

$HTTP["host"] =~ "^website\.com$" { url.redirect = ( "^/(.*)" => "http://www.website.com/forum" ) }


Without results ! But what /$1 at the end means ?
Reply With Quote
  #4 (permalink)  
Old 12-12-2009, 06:33 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
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

$1 will append whatever is there after website.com/url-name. For example, if you type the following
Code:
cyberciti.biz/tips/google-public-dns-servers-launched.html
It will be redirected to
Code:
www.cyberciti.biz/tips/google-public-dns-servers-launched.html
  1. $1 is /tips/google-public-dns-servers-launched.html
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #5 (permalink)  
Old 12-12-2009, 06:56 PM
Junior Member
User
 
Join Date: Jun 2009
OS: Debian
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 0
maxtox is on a distinguished road
Default

Thanks for the explication.

And for the redirection do you have idea ?

Because i don't have website i have only forum then i want redirect all users to /forum


$HTTP["host"] =~ "^website\.com$" { url.redirect = ( "^/(.*)" => "http://www.website.com/forum" ) }



website.com > work redirect to > website.com/forum
www.website.com return > 404 not found
Reply With Quote
  #6 (permalink)  
Old 12-12-2009, 07:58 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
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

Can you attach or paste your lighttpd.conf file? You must be doing something wrong with config file.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #7 (permalink)  
Old 12-12-2009, 08:03 PM
Junior Member
User
 
Join Date: Jun 2009
OS: Debian
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 0
maxtox is on a distinguished road
Default

This is IT LOL

Quote:
# Debian lighttpd configuration file
#

############ Options you really have to take care of ####################

## modules to load
# mod_access, mod_accesslog and mod_alias are loaded by default
# all other module should only be loaded if neccesary
# - saves some time
# - saves memory

server.modules = (
"mod_access",
"mod_alias",
"mod_fastcgi",
"mod_accesslog",
"mod_compress",
"mod_status",
"mod_rewrite",
"mod_redirect",
# "mod_evhost",
# "mod_usertrack",
# "mod_rrdtool",
# "mod_webdav",
# "mod_expire",
# "mod_flv_streaming",
"mod_evasive"
)

## a static document-root, for virtual-hosting take look at the
## server.virtual-* options
server.document-root = "/var/www/"

## where to upload files to, purged daily.
server.upload-dirs = ( "/var/cache/lighttpd/uploads" )



## files to check for if .../ is requested
index-file.names = ( "index.php", "index.html",
"index.htm", "default.htm",
"index.lighttpd.html" )

###STAT
status.status-url = "/server-status"
status.statistics-url = "/server-counters"



## Use the "Content-Type" extended attribute to obtain mime type if possible
# mimetype.use-xattr = "enable"


## deny access the file-extensions
#
# ~ is for backupfiles from vi, emacs, joe, ...
# .inc is often used for code includes which should in general not be part
# of the document-root
url.access-deny = ( "~", ".inc" )

##
# which extensions should not be handle via static-file transfer
#
# .php, .pl, .fcgi are most often handled by mod_fastcgi or mod_cgi
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )


######### Options that are good to be but not neccesary to be changed #######

## Use ipv6 only if available.
#include_shell "/usr/share/lighttpd/use-ipv6.pl"

## bind to port (default: 80)

#server.port = 80


## bind to localhost only (default: all interfaces)
## server.bind = "localhost"

## error-handler for status 404
#server.error-handler-404 = "/error-handler.html"
#server.error-handler-404 = "/error-handler.php"

## to help the rc.scripts
server.pid-file = "/var/run/lighttpd.pid"

##
## Format: <errorfile-prefix><status>.html
## -> ..../status-404.html for 'File not found'
#server.errorfile-prefix = "/var/www/"

## virtual directory listings
#dir-listing.encoding = "utf-8"
#server.dir-listing = "disable"

## send unhandled HTTP-header headers to error-log
#debug.dump-unknown-headers = "enable"

### only root can use these options
#
# chroot() to directory (default: no chroot() )
#server.chroot = "/"

## change uid to <uid> (default: don't care)
server.username = "www-data"

## change uid to <uid> (default: don't care)
server.groupname = "www-data"

#### compress module
compress.cache-dir = "/var/cache/lighttpd/compress/"
compress.filetype = ("text/plain", "text/html", "application/x-javascript", "text/css")


#### url handling modules (rewrite, redirect, access)
# url.rewrite = ( "^/$" => "/server-status" )
# url.redirect = ( "^/wishlist/(.+)" => "http://www.123.com/$1" )

#
# define a pattern for the host url finding
# %% => % sign
# %0 => domain name + tld
# %1 => tld
# %2 => domain name without tld
# %3 => subdomain 1 name
# %4 => subdomain 2 name
#
# evhost.path-pattern = "/home/storage/dev/www/%3/htdocs/"

#### expire module
# expire.url = ( "/buggy/" => "access 2 hours", "/asdhas/" => "access plus 1 seconds 2 minutes")

#### rrdtool
# rrdtool.binary = "/usr/bin/rrdtool"
# rrdtool.db-name = "/var/www/lighttpd.rrd"

#### variable usage:
## variable name without "." is auto prefixed by "var." and becomes "var.bar"
#bar = 1
#var.mystring = "foo"

## integer add
#bar += 1
## string concat, with integer cast as string, result: "www.foo1.com"
#server.name = "www." + mystring + var.bar + ".com"
## array merge
#index-file.names = (foo + ".php") + index-file.names
#index-file.names += (foo + ".php")


#### external configuration files
## mimetype mapping
include_shell "/usr/share/lighttpd/create-mime.assign.pl"

## load enabled configuration files,
## read /etc/lighttpd/conf-available/README first
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

#### handle Debian Policy Manual, Section 11.5. urls
## by default allow them only from localhost
## (This must come last due to #445459)
## Note: =~ "127.0.0.1" works with ipv6 enabled, whereas == "127.0.0.1" doesn't
$HTTP["remoteip"] =~ "127.0.0.1" {
alias.url += (
"/doc/" => "/usr/share/doc/",
"/images/" => "/usr/share/images/"
)
$HTTP["url"] =~ "^/doc/|^/images/" {
dir-listing.activate = "enable"
}
}



### DDOS PROTECTION
evasive.max-conns-per-ip = 15


## server configuration

server.max-keep-alive-requests = 0
server.max-write-idle = 2000
server.max-read-idle = 100
server.max-connections = 500





fastcgi.server = ( ".php" =>
(( "socket" => "/tmp/php.socket",
"bin-path" => "/usr/bin/php-cgi",
"max-procs" => 5,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "10",
"PHP_FCGI_MAX_REQUESTS" => "500"
),
"broken-scriptfilename" => "enable"
))
)






#################################################G ENERAL SERVER############################################ #########
$HTTP["host"] =~ "server_ip_adress" {

server.document-root = "/var/www"
## where to send error-messages to
server.errorlog = "/var/log/lighttpd/error.log"

#### accesslog module
accesslog.filename = "/var/log/lighttpd/access.log"
}
################################################EN D GENERAL SERVER############################################ #######
################################################## #VHOST





$HTTP["host"] =~ "(^|\.)website\.com$" {

server.document-root = "/home/website.com/public_html"
#server.errorlog = "/home/lighttpd/website.com/error.log"
#accesslog.filename = "/home/lighttpd/website.com/access.log"



}

$HTTP["host"] =~ "^website\.com$" { url.redirect = ( "^/(.*)" => "http://www.website.com/$1" ) }


$HTTP["host"] =~ "files.website.com" {
server.document-root = "/home/files.website.com/html"

}


#seo
url.rewrite-once = (

"^/forum/(sitemap.*\.(xml|txt)(\.gz)?)$" => "/forum/vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1",
"^(/forum/(admincp|modcp|clientscript|cpstyles|images|custom avatars|styles|smiley)/.*)$" => "$1",
"^(/website\.ico|/robots\.txt|.*clear\.gif)$" => "$1",
"^/forum/(.+)$" => "/forum/vbseo.php",
"^/forum/(.+)\?(.*)$" => "/forum/vbseo.php?$2",
)




Reply With Quote
  #8 (permalink)  
Old 16-12-2009, 08:30 PM
Junior Member
User
 
Join Date: Jun 2009
OS: Debian
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 0
maxtox is on a distinguished road
Default

Up !!!!!!!!!!
Reply With Quote
  #9 (permalink)  
Old 02-01-2010, 06:04 PM
vamsi's Avatar
Senior Member
User
 
Join Date: Nov 2009
Location: Bangalore / India
OS: Ubuntu , Debian Lenny , CentOS 5.x
Posts: 109
Thanks: 70
Thanked 7 Times in 5 Posts
Rep Power: 1
vamsi will become famous soon enough
Default

Hi..this will redirect now www visitors to www
PHP Code:
$HTTP["host"] =~ "^domain\.com$" {
   
url.redirect = ( "^/(.*)" => "http://www.domain.com/$1" )

__________________
Reply With Quote
Reply

Tags
lighttpd , lighttpd url rewrite , redirect , seo , url.redirect , url.rewrite-once


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 Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Lighttpd rewrite rules Melnax Web servers 0 01-06-2009 01:51 PM
Drupal/lua rules for lighttpd jtrudeau Web servers 3 07-09-2008 12:20 AM
Lighttpd Gallery2 URL Rewrite (.htaccess) SEO Rules rootadmin Web servers 2 22-06-2008 06:57 PM
Redirect + Rewrite Problem in Lighttpd Lizard King Web servers 4 17-07-2007 09:44 AM
redirect to www in lighttpd muks Web servers 11 02-06-2007 10:55 PM


All times are GMT +5.5. The time now is 03:49 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

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 37 38