1

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

tonito
  • 11
  • 3
  • Possible duplicate of [Apache: How to rewrite URL with no file extension and ignore case?](http://stackoverflow.com/questions/14180176/apache-how-to-rewrite-url-with-no-file-extension-and-ignore-case) – Bor Laze May 14 '17 at 19:16
  • no as that one is using .htaccess. I stated that i have to solve it just with the apache vhost config. – tonito May 14 '17 at 21:23
  • It doesn't make any difference. `.htaccess` or `` rules are exactly the same – Capsule May 14 '17 at 22:53
  • 1
    bullcrap - if you use .htaccess its content is parsed for every request. but if you put any directory specific rewrite rules in your httpd.conf it is only parsed at webserver startup. So in questions of server efficiency this is a HUGE difference if you ever going to use webtechnology for commercial and professional solutions. – tonito May 15 '17 at 13:10
  • you should at least define what "does not work" mean, what happens exactly? what did you expect to happen instead? What kind of request you made? If you don't want to use .htaccess, which is a good thing, you need to set AllowOverride to "none". Your current rules send any request for non-existing files to the same thing .php. But perhaps you just want to send all those to a main controller, such as index.php – Daniel Ferradal May 16 '17 at 12:16

0 Answers0