2016-11-16 46 views
1

我試圖在我的網站上使用mod_rewrite做兩件事。使用mod_rewrite和RewriteRule發生內部服務器錯誤

首先,我想隱藏的URL PHP文件擴展名.. (例如website.com/about.phpwebsite.com/about) 和我有這麼多正常工作。

但我也想簡化網址查詢和爭論,使他們更加搜索引擎優化友好。 (例如website.com/work/item.php?id=item-slug成爲website.com/work/item-slug

這是我的.htaccess文件,到目前爲止,但它給我的內部服務器錯誤...

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/

    RewriteCond %{REQUEST_FILENAME}.php -f 
    RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L] 

    # Interpret "work/(ARG)" as "work/item.php?id=(ARG)" 
    RewriteRule ^work/(*.)$ work/item.php?id=$1 [L] 
</IfModule> 
+0

您確定要將「website.com/work/item.php?id=item-slug」轉換爲「website.com/work/item-slug」嗎?我想,你想要「website.com/work/item/item-slug」。 –

回答

2

你得到500錯誤,因爲*.是無效的正則表達式不能被編譯。此外,您需要跳過上次重寫規則中的文件/目錄。

Options -MultiViews 
RewriteEngine On 
RewriteBase/

# Interpret "work/(ARG)" as "work/item.php?id=(ARG)" 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^work/([\w-]+)/?$ work/item.php?id=$1 [L,QSA,NC] 

RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.+?)/?$ $1.php [L] 
+1

非常感謝!工作完美無缺:) – Splycd

相關問題