Sushant
Sushant

Reputation: 55

How to add ".php" extension using ".htaccess" file

Need to Modify .htaccess file so that

www.abc.com/uid?1pd47f4s4g28a3f

Should get redirected to

www.abc.com/uid.php?id=1pd47f4s4g28a3f

I tried below Codes :

#short link
Options +MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^(.+)\.php$ /$1 [R,L]
RewriteCond %uid.php -f
RewriteRule ^(.*?)/?$ /$1.php [NC,END]

Upvotes: 2

Views: 468

Answers (1)

RavinderSingh13
RavinderSingh13

Reputation: 133538

Considering that you want to check if filename(from uri).php is present on local filesystem then you need to redirect request to that specific file without rewriting url in browser, if this is the case please try following.

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php?id=%{QUERY_STRING} [END]

NOTE: In above rules change from END to L in case you have further more rules.

Upvotes: 2

Related Questions