簡體   English   中英

使用mod_rewrite和RewriteRule的內部服務器錯誤

[英]Internal Server Error with mod_rewrite and RewriteRule

我正在嘗試將mod_rewrite用於網站上的兩件事。

首先,我想在URL中隱藏.php文件擴展名。(例如, website.com/about.phpwebsite.com/about ),並且我可以正常工作。

但我也想通過查詢和參數來簡化URL,以使其對SEO更友好。 (例如, 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>

您收到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]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM