RewriteRule在.htaccess文件中不起作用

时间:2012-07-06 00:51:03

标签: php html .htaccess mod-rewrite redirect

我在Stack上发现了几个有很多很多例子的问题,但是我已经尝试了书中的每个人,但是拒绝工作。

我正在尝试转换。

www.domain.com/title/index.php?id=70048305

www.domain.com/title/70048305

我希望它可以双向转换。当他们输入查询字符串并使用干净的网址时。

我的重写有什么问题?

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^title/(.+)$ index.php?id=$1 [L,QSA]

我应该注意,我已将此.htaccess文件放在根目录和/ title /文件夹中。

2 个答案:

答案 0 :(得分:1)

试试这个

RewriteEngine On

RewriteRule ^([a-zA-Z0-9-+/]+)$ index.php?id=$1
RewriteRule ^([a-zA-Z0-9-+/]+)/$ index.php?id=$1

答案 1 :(得分:0)

不匹配^title/(.+)$您需要仅匹配^title/([\d]+)/?

之类的数字

否则,

www.domain.com/title/index.php?id=70048305

将匹配并重定向到:

index.php?id=index.php?id=70048305