Patoliya Nitin
Patoliya Nitin

Reputation: 70

Add slash end of the URL after remove .php from file using .htaccess

I want to add slash end of the url after remove .php from file. For ex. www.xyz.com/abc/

I have used below .htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php**strong text**

Upvotes: 1

Views: 427

Answers (1)

Pinke Helga
Pinke Helga

Reputation: 6692

You might want this

RewriteEngine On
# where the .htaccess file is located (public path from document_root)
RewriteBase /subdir/path/based/on/document_root


# does not apply to existing directories
RewriteCond %{REQUEST_FILENAME} !-d
# rewrite dir-like urls to php script and  END rewriting to avoid infinite loop
RewriteRule (.*)/ $1.php [END]

# apply to existing files only
RewriteCond %{REQUEST_FILENAME} -f
# browser redirect to canonical URL
RewriteRule (.*)\.php$ $1/ [L,R=301]

Upvotes: 1

Related Questions