简体   繁体   English

如何使用mod_rewrite与CMS一起删除查询字符串

[英]How to use mod_rewrite to remove a query string withing a CMS

I'm using a CMS that sends all requests to an index.php file using the following RewriteRule 我正在使用CMS,使用以下RewriteRule将所有请求发送到index.php文件

RewriteRule .* index.php [L]         

However in the news section of the site the CMS is generating news links like this: /news?month=201106 但是,在该网站的新闻部分中,CMS生成的新闻链接如下: /news?month=201106

I want my news links like this: /news/month/201106 and I will achieve this with PHP code. 我希望我的新闻链接是这样的: /news/month/201106 ,我将用PHP代码来实现。

I know pretty much how to achieve the rewrite with Apache if it weren't for that catchall I would use something like this: 我不知道如何使用Apache实现重写,如果不是那样的话,我会使用如下代码:

RewriteRule ^news/month/(.+)$ news?month=$1 

However my problem is that the CMS is catching the calls and trying to find /news/month/201106 which it cannot and throws an CMS level 404 但是我的问题是,CMS正在捕获呼叫,并尝试查找/ news / month / 201106,它不能并抛出CMS级别404

I've read up about making exceptions but I can't work out how to get: 我已经阅读了有关制作例外的信息,但无法弄清楚如何获取:

  1. Apache to catch the rewrite before it gets sent to the catch all Apache在将重写发送到全部捕获之前对其进行捕获
  2. The CMS to then process the rewritten URL as normal (ie: receive news?month=201106 and process that as normal) CMS然后按正常方式处理重写的URL(即:接收新闻?month = 201106并按正常方式处理该URL)

I'm sure this is probably down to the Rewrite flag and the order in which these directives are written but I just cannot get it to work. 我确定这可能取决于Rewrite标志和这些指令的写入顺序,但我无法使其正常工作。

1) Apache to catch the rewrite before it gets sent to the catch all 1)Apache在将重写发送到catch全部之前对其进行捕获

You can do this by adding a RewriteCond before your RewriteRule .* index.php [L] , so that it looks something like this: 您可以通过在RewriteRule .* index.php [L]之前添加RewriteCond来做到这一点,从而使其看起来像这样:

RewriteCond %{REQUEST_URI} !^/news
RewriteRule .* index.php [L]

2) The CMS to then process the rewritten URL as normal (ie: receive news?month=201106 and process that as normal) 2)CMS然后按正常方式处理重写的URL(即:接收新闻?month = 201106并按正常方式处理该URL)

The 2nd rule that you had, RewriteRule ^news/month/(.+)$ news?month=$1 should take care of that. 您拥有的第二条规则RewriteRule ^news/month/(.+)$ news?month=$1应该可以解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM