Archive

Posts Tagged ‘lighttpd rewrite url character dot’

Problem with Lighttpd Rewrite url and character ‘dot’

vấn đề rewrite với lighttpd còn khá mới mẻ. lighttpd chưa phố biến như apache, nên các tài liệu về rewrite của lighttpd còn rât hạn chế, ngay cả trang chủ của lighttpd cũng chỉ có các khái niệm rewrite của lighttpd ở dạng cơ bạn. Tùy thuộc vào ứng dựng web của bạn có đường dẫn phức tạp như thế nào để phát triển thêm.

Về cơ bản bạn chỉ cần rewrite như dưới đây là web có thể chạy ứng dụng web.

http://www.mydomain.com/news/123 //work OK

$HTTP[“host”] =~ “^(www\.)?mydomain.com$” {
server.document-root = “/var/www/lighttpd/my_app”
server.error-handler-404 = “/index.php”

url.rewrite-once = (
“/(.*)\.(.*)” => “$0”,
“/(css|files|img|js|stats)/” => “$0”,
“^/([^.]+)$” => “/index.php/$1”
)
}

Nhưng với các ứng dựng web có đường dẫn phức tạp hơn
Ví dụ: http://www.mydomain.com/member/target?op=123email=test@yahoo.com //not work
thì đoạn rewrite bên trên của lighttpd sẽ không xử lý được. Ứng dựng không làm việc

Dưới đây tôi hướng dẫn các bạn cấu hình lighttpd rewrite với url xuất hiện ký tự dấu chấm (dot)

$HTTP[“host”] =~ “^(www\.)?mydomain.com$” {
server.document-root = “/var/www/lighttpd/my_app”
server.error-handler-404 = “/index.php”
url.rewrite-once = (
“^/(css|images|upload|sf|files|img|js|stats)/(.*)” => “$0”,
“^/([^.*]+)\.([^.*]+)$” => “/index.php/$1.$2”,
“^/([^.*]+)$” => “/index.php/$1/”
)
}

Lúc này đường dẫn url http://www.mydomain.com/member/target?op=123email=test@yahoo.com chạy OK.

Chúc các bạn thành công

Tham khảo thêm Regular Expressions của lighttpd

• . (full stop) – match any character
• \* (asterisk) – match zero or more of the previous symbol
• \+ (plus) – match one or more of the previous symbol
• ? (question) – match zero or one of the previous symbol
• \\? (backslash-something) – match special characters
• ^ (caret) – match the start of a string
• $ (dollar) – match the end of a string
• [set] – match any one of the symbols inside the square braces.
• [^set] – match any symbol that is NOT inside the square braces.
• (pattern) – grouping, remember what the pattern matched as a special variable
• {n,m} – from n to m times matching the previous character (m could be omitted to mean >=n times)
• (?!expression) – match anything BUT expression at the current position. Example: “^(/(?!(favicon.ico$|js/|images/)).*)” => “/fgci/$1”
• Normal alphanumeric characters are treated as normal

nhantam
Web Developer