2016-09-18 58 views
-2

我使用的是Godaddy的域名,我想阻止/擺脫我的文件擴展名,例如:www.example.com/index.phpwww.example.com/index塊.PHP .html擴展

我知道的.htaccess的所以這裏是我的代碼重寫規則

<IfModule mod_rewrite.c> 
Options +FollowSymLinks 
RewriteEngine On 
RewriteBase/

# Add trailing slash to url 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$ 
RewriteRule ^(.*)$ $1/ [R=301,L] 

# Remove .php-extension from url 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^([^\.]+)/$ $1.php 

# Remove .html-extension from url 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^([^\.]+)/$ $1.html 

</IfModule> 

有人幫我請。

+1

你面對的是什麼問題? –

+0

我想你使用的是godaddy windows hosting嗎? – phpdroid

+0

@AyushGupta有沒有問題,但它不工作沒有錯誤 –

回答

1

在Apache上

因爲你在GoDaddy的,您需要啓用多視圖中的.htaccess文件。

添加以下代碼:

Options +MultiViews 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.php [NC,L] 

應該工作。參考:https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/

在IIS/Windows的

IIS使用web.config文件而不是.htaccess文件。創建在根目錄下的文件web.config中(或你想要的規則適用每個目錄),並把下面的代碼在它

<rewrite> 
    <rule name="hide .php extension" stopProcessing="true"> 
    <match url="(.*)" /> 
     <conditions> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
     </conditions> 
    <action type="Rewrite" url="{R:1}.php" /> 
    </rule> 
</rewrite> 

參考:https://www.saotn.org/iis-url-rewrite-hide-php-extension/

+0

這不工作也先生:(。我需要重新配置所有的HREF鏈接? –

+0

你在@PaulKevin上託管?Apache ,IIS或其他什麼東西? –

+0

Plesk ??即時通訊不是很確定。哈哈哈,但即時通訊使用godaddy –