How-to? Vanity URL & ignore .PHP extension with .htaccess

别来无恙 提交于 2019-12-01 12:23:38
mario

It's a matter of ordering. RewriteRules are applied in the order they are noted in the .htaccess
See Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask?

Just add your new block as first rewrite statement, add a [LAST] flag, and it should work.

This rule works unconditionally (not guarded by any RewriteCond), so should always be the last of all RewriteRules:

 RewriteRule ^(.*)$ ...

(And all preceeding RewriteRules should preferrably carry a [L] flag. You have a bit of a workaround there.)

For me this code work:

in "/etc/apache2/sites-available/default" or "httpd.conf"

you must have (at least) these options in the default directory

...
    <Directory />
        ...
        Options FollowSymLinks
        AllowOverride All
        ...
    </Directory>
...

OR in the site specific site directory

...
    <Directory "/var/www/my-site">
        ...
        Options FollowSymLinks
        AllowOverride All
        ...
    </Directory>
...

and create or edit the ".htacces" in the directory of the site (for example "/var/www/my-site/.htaccess") and add this code:

AddType application/x-httpd-php htm html php
AddHandler application/x-httpd-php .htm .html

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!