简体   繁体   English

使用.htaccess重写ID为“找不到页面”的网址

[英]Using .htaccess to rewrite urls with ID: “Page not found”

I am trying to rewrite some urls by using the .htaccess file in a WordPress environment. 我正在尝试通过在WordPress环境中使用.htaccess文件重写一些URL。 I have a WordPress page called "offerta" with two parameters, one of them is a custom ID that I use to generate content. 我有一个名为“ offerta”的WordPress页面,带有两个参数,其中一个是我用来生成内容的自定义ID。

so, an example url is: http://www.riccionelastminute.it/rlm/offerta/?id=15&titolo=my-title 因此,示例网址为: http : //www.riccionelastminute.it/rlm/offerta/?id=15& titolo=my- title

and I would like it to be: http://www.riccionelastminute.it/rlm/offerta/my-title-15/ 我希望它是: http : //www.riccionelastminute.it/rlm/offerta/my-title-15/

this is my .htaccess right now: 这是我现在的.htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /rlm/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /rlm/index.php [L]
</IfModule>

# END WordPress

After some research, I tried to add this rule right after the last Rewrite Rule, but it redirects to a 404 page: 经过研究,我尝试在最后一个重写规则之后立即添加此规则,但是它重定向到404页面:

RewriteRule ^offerta/([A-Za-z0-9-]+)-([0-9]+)/$ offerta/?id=$2&titolo=$1

I'm not used to play around .htaccess and I'm not an expert. 我不习惯玩.htaccess,而且我也不是专家。 Am I missing something? 我想念什么吗?

The problem is that the last RewriteRule has the L flag which means that no other rules are applied after it . 问题是最后一个RewriteRule具有L标志,这意味着之后没有其他规则可应用 What you need to do is add your rule before the last one: 您需要做的是在最后一个规则之前添加规则:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /rlm/
RewriteRule ^index\.php$ - [L]

RewriteRule ^offerta/([A-Za-z0-9-]+)-([0-9]+)/$ offerta/?id=$2&titolo=$1

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /rlm/index.php [L]
</IfModule>

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

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