Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
465 views
in Technique[技术] by (71.8m points)

php - .htaccess; no extension required

I need some .htaccess code that will treat extensionless files as PHP files.

Suppose the visitors visits www.mywebsite.com/dir1/dir2/file.name, it will first look the file dir1/dir2/file.name exists and if it not exists, it will look for dir1/dir2/file.name.php (so with .php extension).

Is that possible in some way?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can write a rewriting rule which only takes into effect if the requested file doesn't exists.

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !.php$
RewriteRule ^(.*)$ $1.php [L]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...