将类似目录的URL后缀重写为GET参数

时间:2013-01-29 21:38:41

标签: apache mod-rewrite

鉴于以下设置,我想做一个我无法工作的mod_rewrite:

我有一个域名,例如“example.org”指向共享托管环境中的目录,例如example/具有以下文件结构:

example/
    index.php
    .htaccess

现在应将example.org/test之类的网址重写为example.org/index.php?p=test。我想出的是以下内容:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]+)$ index.php?p=$1 [L,QSA]

不幸的是打开例如Firefox中的example.org/test会导致以下错误:

页面未正确重定向

Firefox检测到服务器正在以永远无法完成的方式重定向此地址的请求。

  • 有时可能会因禁用或拒绝接受Cookie而导致此问题。

但是,如果我在匹配部分前面加上这样的前缀:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^prefix/([a-z]+)$ index.php?p=$1 [L,QSA]

然后我可以打开例如example.org/prefix/test我已尽快与index.php?p=test一起投放,但未正确引用CSS和JavaScript等其他资源。

谁可以提供帮助?

0 个答案:

没有答案