簡體   English   中英

使用mod_rewrite清理URL會產生500個內部服務器錯誤

[英]mod_rewrite for clean urls gives 500 internal server error

我在使用mod_rewrite時遇到了一些麻煩。

在我的索引頁面(index.php)上,顯示一個博客,單個博客帖子頁面如下所示: http : //www.mydomain.com/blog/post-title

mod_rewrite為此:

RewriteRule ^blog/([A-Za-z0-9-]+)$ index.php?postslug=$1 [L]

這就像一個魅力。

但我還有另一個頁面,名為Artists.php,網址應如下所示: http : //www.mydomain.com/artists/artist-name

mod_rewrite為此:

RewriteRule ^artists/([A-Za-z0-9-]+)$ artists.php?artistslug=$1 [L]

這給了我500個內部服務器錯誤,我不知道為什么會發生這種情況...

index.php和artist.php都在我網站的根目錄中

.htaccess文件:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

RewriteRule ^blog/([a-z0-9\-]+)$ index.php?postslug=$1 [L]
RewriteRule ^artists/([a-z0-9\-]+)$ artists.php?artistslug=$1 [L]

嘗試使用此規則,而不是兩個RewriteCond

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
RewriteRule ^(.*)$ $1.php [L]

我已經對其進行了測試, %{REQUEST_FILENAME}似乎包含錯誤的值,但無論如何-f被評估為true

打開:

RewriteLog /path/to/file.log
RewriteLogLevel 4
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -f [NC,OR] 
RewriteCond %{REQUEST_FILENAME} -d [NC] 
RewriteRule .* - [L]

RewriteRule ^blog/([-A-z0-9]+)$ index.php?postslug=$1
RewriteRule ^artists/([-A-z0-9]+)$ artists.php?artistslug=$1

RewriteRule本身對我來說看起來不錯,如果直接訪問Artists.php文件而不進行URL重寫,請檢查服務器是否發生錯誤。

暫無
暫無

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

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