salep
salep

Reputation: 1390

htaccess rewrite rule to remove subfolders

I want to change

example.com/modules/page/page.php

to

example.com/page 

I have a RewriteRule that works partially, but there's a problem.

RewriteRule ^page/(\w+)/? modules/page/page.php?page_id=$1 [NC,L]

page.php can be accessed if I type example.com/page/randomstring

I want this to be valid for only example.com/page

How can I achieve that?

Upvotes: 0

Views: 71

Answers (1)

xcvd
xcvd

Reputation: 696

In your .htaccess file

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9]+)$ modules/page/page.php?page_id=$1 [L,QSA]

Upvotes: 1

Related Questions