.htaccess; no extension required

前端 未结 3 789
迷失自我
迷失自我 2020-12-18 04:03

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

相关标签:
3条回答
  • 2020-12-18 04:17

    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]
    
    0 讨论(0)
  • 2020-12-18 04:30

    You should have a look at Apache's Options directive, most specifically the http://httpd.apache.org/docs/2.0/content-negotiation.html option which you can include in your .htaccess file and will do just that.

    Add to your .htaccess:

    Options +MultiViews
    
    0 讨论(0)
  • 2020-12-18 04:31

    Ok, the answer was a combination of answers. I needed to add Options +MultiViews in my Apache configuration. Then I extend Andrews answer to the following:

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

    Regards and many thanks! Kevin

    0 讨论(0)
提交回复
热议问题