简体   繁体   中英

.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'd say that

RewriteCond %{REQUEST_FILENAME}\.php -f

is unnecessary. What shall that be for?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM