.htaccess rewrite URL with two variables

I have a problem with my rewrite rule .htaccess(I'm new to this, so maybe it's easy)

I have a url that:

http://www.example.com/film-al-cinema/?titolo=Ghost+in+the+Shell&id=315837

So, I have the movie name inside the first variable titolo=""and the movie id in the second variable id="".

I want the url to look like

http://www.example.com/film-al-cinema/Ghost+in+the+Shell/315837

I tried to modify the htaccess file as follows:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^film-al-cinema/(.*)/([0-9]+)$ film-al-cinema/?titolo=$1&id=$2 [R]
</IfModule>

but it redirects me to page 404

EDIT

I am working on Wordpress, therefore it /film-al-cinema/is a Wordpress page

EDIT 2

# BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

RewriteRule ^film-al-cinema/([^/]+)/(\d+)/?$  /index.php?page_id=21016&titolo=$1&id=$2 [L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>

# END WordPress
+4
source share
1 answer

, (),

 RewriteEngine On
 RewriteCond %{THE_REQUEST} ^GET\ /film-al-cinema\/\?titolo=([^\s&]+)&id=([^\s&]+) [NC]
 RewriteRule ^film-al-cinema\/$ /film-al-cinema/%1/%2? [R,L]
 RewriteRule ^film-al-cinema/([^/]+)/([^/]+)/?$ /film-al-cinema/?titolo=$1&id=$2 [NC,L]

.htaccess, . , R=301 R

0

Source: https://habr.com/ru/post/1676235/


All Articles