【发布时间】:2011-02-04 07:28:01
【问题描述】:
我想要达到的目标:
1) http://localhost/en/script.php?param1=random 映射到 http://localhost/script.php?param1=random&language=English
- 这必须始终有效。
2) http://localhost/en/random/text/here 将映射到 http://localhost/categories.php?term=random/text/here
- 如果 random/text/here 是 404,这必须有效
我现在拥有的:
RewriteEngine on
RewriteCond substr(%{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^en/(.+)$ categories.php?lang=English&terms=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ee/(.+)$ categories.php?lang=Estonian&terms=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^fi/(.+)$ categories.php?lang=Finnish&terms=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ru/(.+)$ categories.php?lang=Russian&terms=$1 [L]
RewriteRule ^en/(.*) $1?lang=English [QSA]
RewriteRule ^ee/(.*) $1?lang=Estonian [QSA]
RewriteRule ^ru/(.*) $1?lang=Russian [QSA]
RewriteRule ^fi/(.*) $1?lang=Finnish [QSA]
有什么问题:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
它应该重定向到 categories.php?lang=English IF /en/this/here/does/not/match/a/script。如果我加载像 en/index.php 这样的 URL,它也会映射到 categories.php?lang=English,因为 en/index.php 不存在。
我的想法:
substr(%{REQUEST_FILENAME},3) 可以解决我的问题(因为目前 /ee/index.php 被逐字映射到 /ee/index.php 而不仅仅是 /index.php)
不幸的是,我找不到操作字符串的方法:/
【问题讨论】:
标签: apache mod-rewrite friendly-url