How to modrewrite in my htaccess?

Why my .htacces is not working? I have got pages:

site.com/page.php

I want to see pages, like this:

site.com/page/

htacces here:

RewriteEngine On
RewriteBase /
RewriteRule /(.*).php /$1

Also I want to see redirect from page.php to /page/ too

How?

Upvotes: 1

Views: 10

Answers (1)

anubhava
anubhava

Reputation: 784958

You can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On
RewriteBase /

# To externally redirect /dir/file.php to /dir/file
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]

# To internally forward /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

Upvotes: 1

Related Questions