需要Apache重写规则来更改部分url [英] Need Apache rewrite rule to change part of url

查看:129
本文介绍了需要Apache重写规则来更改部分url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的网址:

www.example.com/ index.php/category-5 /subcategory/page

www.example.com/index.php/category-5/subcategory/page

我想重写为:

www.example.com/类别/子类别/页面

www.example.com/category/subcategory/page

即我想删除"index.php/",也要删除"-5",但保留其余部分.

I.e. I want to remove the "index.php/" and also remove the "-5", but keep the rest.

我对Apache感到困惑.我通常只写简单的简单php代码.

I am in way over my head with Apache. I normally just write plain simple php code.

我尝试了一下,但是没有用:

I tried this and it didn't work:

RewriteRule ^index.php/category-1/(.*)$ /category/($1) [NC]

谢谢

还请,如果我们可以将其设为永久重定向,那就太好了.

Also, please, if we could make it a permanent redirect that would be great.

推荐答案

在替换部分中不要使用括号:

Don't use parenthesis in the replacement part:

RewriteRule ^ index.php/category-1/(.*)$/category/$ 1 [NC,R = 301]

RewriteRule ^index.php/category-1/(.*)$ /category/$1 [NC,R=301]

请参阅:

http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriteoptions

http://httpd.apache.org/docs/current/rewrite/flags.html

您可以激活调试日志,因为RewriteRule非常棘手,所以我一直发现这很有用:

you could activate debug logs, I've always found this useful as RewriteRule are tricky:

RewriteLog "/path-to-log/rewrite.log"
RewriteLogLevel 4

这篇关于需要Apache重写规则来更改部分url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆