mod rewrite - handle url request without php extension

谁说胖子不能爱 提交于 2021-01-28 06:36:39

问题


i want server requests without .php ending to be handled like they had .php. for example http://example.com/exampleSite is requested by the user. How can i use a rewrite rule to handle it like it was requested as http://example.com/exampleSite.php? I do not want to use .htaccess (as it is recommended to put rewrite rules into a directory block inside the apache vhost config. And i only want this to affect my php files in the root directory.

The following config unfortunately does not work.

<VirtualHost *:80>
    DocumentRoot /var/www/examplesite

    <Directory /var/www/examplesite>
            IndexIgnore * # prevent directory listing
            DirectoryIndex index.php
            Options FollowSymLinks MultiViews
            AllowOverride All
            Require all granted
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule (.*) $1.php [L] 
    </Directory>

    ErrorLog /xvar/xlog/error.log
    CustomLog /xvar/xlog/access.log combined

来源:https://stackoverflow.com/questions/43967770/mod-rewrite-handle-url-request-without-php-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!