Access /index.php as /index (without ".php")

Asked

Viewed 614 times

0

Using regular expressions, I can check index.html pages as index but not index.php pages as index. My . htaccess.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /login.php [L]
RewriteRule ^index$ index.html [NC,L]
</IfModule>

Inside my Apache, at the address /etc/apache2/sites-available, I have the default virtual host and I have the virtual host esms.com with the following content:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/var/www/html/meus_projetos/E-SMS-DEVEL"
    ServerName www.esms.com
    ServerAlias esms.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

Allowoverride All

    <Directory /var/www/html/meus_projetos/E-SMS-DEVEL>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Based on this information, I’d like help understanding what I’m doing wrong.

1 answer

1

It wouldn’t just replace . html with . php:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /login.php [L]
RewriteRule ^index$ index.php [NC,L]

Or you can try doing this that would suit any php file:

RewriteRule ^([a-z0-9]+)$ $1.php [NC,L]

You can also try using the mod_negotiation

Browser other questions tagged

You are not signed in. Login or sign up in order to post.