我正在尝试以以下形式重写我的网址
localhost/myapp/view/something or
localhost/myapp/crud/something
到
localhost/myapp/view.pl?view=something or
localhost/myapp/crud.pl?action=something
所有其他请求应该像这样映射:localhost/myapp/login to localhost/myapp/login.pl
我用这个 .htaccess 文件尝试过,但如果我启用最后一个 RewriteRule,我会得到递归,我不明白为什么,因为我用 RewriteCond 保护了它。这是我的第一个 .htacces mod_rewrite 文件,所以请耐心等待我;)
RewriteEngine On
RewriteRule ^/?crud/([^/]*)$ /myapp/crud.pl?action=$2 [QSA]
RewriteRule ^/?view/([^/]*)$ /myapp/view.pl?view=$2 [QSA]
RewriteCond $1 !^/(view|crud)$
RewriteRule ^/?([^/]*)$ /myapp/$1.pl [QSA]
更新:
我删除了前导 / 并添加了 [L] 标志,现在我在 apache 的 error.log 中收到以下错误:
[Mon Jul 09 11:55:33 2012] [error] [client 127.0.0.1] File does not exist: /srv/http/myapp/myapp
新文件:
RewriteRule ^crud/([^/]*)$ myapp/crud.pl?action=$2 [L,QSA]
RewriteRule ^view/([^/]*)$ myapp/view.pl?action=$2 [L,QSA]
RewriteCond $1 !^(view|crud)$
RewriteRule ^([^/]*)$ myapp/$1.pl [QSA]