Apache mod_rewrite,URL重写然后重定向问题

时间:2010-11-14 12:57:25

标签: apache mod-rewrite

我遇到mod_rewrite问题。我想这样做:

我有网址的形式 mydomain.com/index.php/tag/123/some-name /

我想将此网址更改为mydomain.com/some-name /

我在.htacess文件中写了下面的代码,这不起作用: - (

首先重写

RewriteCond%{THE_REQUEST} ^ / index.php / tag /(。)/ $ [NC] RewriteRule ^ index.php / tag /([0-9] +)/(。)/ $ / $ 2 / [R = 301,L]

然后重定向到index.phe

RewriteRule ^(。*)/ $ /index.php?tagname=$1 [L]

我的网址没有在浏览器中重写,也没有转到index.php。

提前致谢, 拉维

1 个答案:

答案 0 :(得分:0)

如果需要标签号来访问正确的页面,则必须做的不仅仅是使用mod_rewrite ...

否则,这就是你要找的东西:

RewriteRule ^index.php/tag/[0-9]+/(.*)$ $1 [R]
RewriteRule ^(.*)$ index.php?tagname=$1 [L]

现在有人访问:mydomain.com/tag/123/wierdtagname将被重定向到mydomain.com/wierdtagname,它将运行mydomain.com/index.php?tagname=wierdtagname