astralmaster
astralmaster

Reputation: 2465

.htaccess remove extension for a single file

Is there a possibility to redirect requests for example.com/test to example.com/test.php for a particular file using .htaccess, leaving all other files/extensions intact?

Upvotes: 5

Views: 1425

Answers (3)

Ajeet Kumar
Ajeet Kumar

Reputation: 815

you can use

RewriteEngine On
RewriteRule ^test$ test.php

Upvotes: 2

Vivek Tankaria
Vivek Tankaria

Reputation: 1311

You can try this : RewriteRule ^test$ /test.php [L] place it above your generic redirection written for all site url.

Like for example :

RewriteRule ^test$ /test.php [L] --page wise condition 

RewriteRule ^/?$ "http\:\/\/example\.com\/" [R=301,L] -- generic for site

RewriteRule ^(.[^\.]*)$ index.php?$1 [QSA,L] -- generic for site

Upvotes: 3

Anup Saund
Anup Saund

Reputation: 335

Yes,

All you do is put this right at the beginning of your .htaccess file

RewriteRule ^test test.php [L]

The [L] means it will honor this line and ignore any subsequent lines.

So put all other URL rewrites after this one.

Upvotes: 0

Related Questions