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. I have a WordPress page called “offerta” with two parameters, one of them is a custom ID that I use to generate content.

so, an example url is: http://www.riccionelastminute.it/rlm/offerta/?id=15&titolo=my-title

Read More

and I would like it to be: http://www.riccionelastminute.it/rlm/offerta/my-title-15/

this is my .htaccess right now:

# 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:

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.
Am I missing something?

Related posts

1 comment

  1. The problem is that the last RewriteRule has the L flag which means that no other rules are applied after it. 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>
    

Comments are closed.