2013-02-10 70 views
2

我试图改变这一点:htaccess的正则表达式改写

/news/index.php?id=101 &标题=这 - 是 - 一 - 超长标题

为此:

/新闻/这 - 是 - 一 - 超长标题/

与htaccess的[R ewrite规则。任何想法如何?

我曾尝试:

Options +FollowSymLinks 
RewriteEngine On 
RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteRule ^.+/news/index.php?title=$1 [NC,L,R] 
+0

[你尝试过什么?](http://www.whathaveyoutried.com/) – Nightfirecat 2013-02-10 04:54:54

+0

@Nightfirecat:!选项+的FollowSymLinks RewriteEngine叙述 在 的RewriteCond%{} SCRIPT_FILENAME -d 的RewriteCond%{} SCRIPT_FILENAME -f RewriteRule ^。+/news/index.php?title = $ 1 [NC,L,R] – user2002495 2013-02-10 04:59:14

回答

1

我觉得这是你所需要的:

Options +FollowSymLinks 
RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_URI} !index\.php [NC] 
RewriteRule ^.*/([^/]+)/? news/index.php?id=101&title=$1 [L,NC] 

地图默默

http://example.com/news/this-is-a-very-long-title/带或不带斜线

要:

http://example.com/news/index.php?id=101&title=this-is-a-very-long-title

在您的规则中,字符串id=101&未出现在替换网址中,因此如果不需要,请将其从重写规则中删除。

对于永久和可见重定向,请将[L,NC]替换为[R=301,L,NC]

+0

谢谢,但我需要的其实是相反的。我想要的是映射_http://example.com/news/index.php?id = 101&title = this-is-a-very-long-title_ to _http://example.com/news/this-is- A-超长标题/ _。我会尝试你的解决方案来做相反的事情。 – user2002495 2013-02-11 06:22:33