How to remove the page alias from url with htaccess?

bytingo

I have created my own cms and i find the following issue. The pages links show as this:

https://www.example.com/page/contact-us

I want them to show as this, by removing the page alias:

https://www.example.com/contact-us

My Htaccess:

Options -MultiViews
RewriteEngine On

RewriteRule ^page/([\s\S]*)$ single-page.php?slug=$1 [L]

I have tried this but doesn't work for me

RewriteEngine On
RewriteRule ^([^/]*)$ /page/single-page.php?slug=$1 [L]
anubhava
RewriteRule ^([^/]*)$ /page/single-page.php?slug=$1 [L]

This won't work because it is forwarding all URIs to /page/ directory which obvious doesn't exist.

You should be using this rule:

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ single-page.php?slug=$1 [L,QSA]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related