2010-10-02 90 views
0

你好,我正在努力使它,以便當你訪問我的網站時,你不必把.php結尾這是我正在使用,但它不工作(godaddy託管).htaccess mod_rewrite

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

我今天剛添加了「Options +FollowSymlinks」,它仍然沒有工作。 非常感謝

+0

你確定mod_rewrite並啓用nd工作?你有沒有嘗試其他規則? – Gumbo 2010-10-02 12:35:47

+0

我是新來的這個我怎麼啓用mod_rewrite – DonJuma 2010-10-02 12:37:09

+0

@Matthew Carter:嘗試一個非常簡單的規則,比如'RewriteRule^http://example.com/?'。 – Gumbo 2010-10-02 12:38:11

回答

0

我還不知道什麼是「的FollowSymLinks」確實,但其餘的這是否:

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 

告訴它在人的話: 如果請求的文件名不是一個目錄,如果你追加。 PHP來該文件名,它是現有的文件然後執行該追加.php後綴的pool

這個工作對我的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> 
0

我想說的是

RewriteCond %{REQUEST_FILENAME}\.php -f 

是不必要的。這是爲了什麼?

+0

我不知道我只是GOOGLE了它 – DonJuma 2010-10-02 12:33:14

+0

這將避免無限遞歸,因爲只有請求被重寫,才能正確地映射到現有的'.php'文件。 – Gumbo 2010-10-02 12:35:12

+0

是錯誤的,因爲它給了我一個404 – DonJuma 2010-10-02 12:36:11