开发者

.htaccess mod_rewrite

hello i am trying to make it so that when you visit my site you don't have to put .php at the end this is what i am using but it isn开发者_如何学运维't working (godaddy hosting)

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

i just added the "Options +FollowSymlinks" today and it still didn't work. Thanks a lot


i don't know yet what the "FollowSymLinks" does but the rest does that:

RewriteEngine On            <-- activates mod rewrite
RewriteCond %{REQUEST_FILENAME} !-d  <-- condition that says: request filename is not directory
RewriteCond %{REQUEST_FILENAME}\.php -f  <-- condition that says: request filename with the appendix .php is a file
RewriteRule ^(.*)$ $1.php  <-- take anything you get and put a .php behind it

to tell it in human words: if the requested filename is not a directory and if you append .php to that filename and it is an existing file then do the rewrite rule which appends .php to the requested file

this works on my XAMPP:

<IfModule mod_rewrite.c>
    RewriteEngine On            
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>


I'd say that

RewriteCond %{REQUEST_FILENAME}\.php -f

is unnecessary. What shall that be for?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜