0

I want to rewrite all links on a certain basis, looking for the value of a segment of their url. With .htaccess I was able to redirect one link, but when I try to make it as a rule, I fail. I suppose a bad syntax, here is my code.

# here single rewrite, works like a charm.
RewriteRule ^francais/Projects/template/297_tsf/dsource/projects\.xml$ http://www.mysite.com/mobile/fr/index.php/xml/projet/297_tsf/file.xml

# uh oh, trying to write a real rule, doesn't works at all.
RewriteRule ^francais/Projects/template/([a-z0-9]+)/dsource/projects\.xml$ http://www.mysite.com/mobile/fr/index.php/xml/projet/$1/file.xml [NC] [L]

any idea?

4

1 回答 1

0

这是正确的语法:

RewriteRule ^francais/Projects/template/([a-z0-9]+)/dsource/projects\.xml$ /mobile/fr/index.php/xml/projet/$1/file.xml [NC,L]

您的标志为:

[NC] [L]

那是不正确的语法,它应该像我在上面的答案中显示的那样。

参考:Apache mod_rewrite 简介

PS:http://www.mysite.com从目标 URL 中删除,因为您使用的是静默(内部)重写,并且由于存在完整的 URL,http://它将成为外部重定向。但是,如果您真的想要外部重定向,请使用:

RewriteRule ^francais/Projects/template/(\w+)/dsource/projects\.xml$ /mobile/fr/index.php/xml/projet/$1/file.xml [NC,L,R]
于 2013-10-02T18:15:07.423 回答