簡體   English   中英

添加mod_rewrite規則會導致整個目錄出現服務器錯誤

[英]Adding mod_rewrite rule causes server error for whole directory

我有一個測試文件夾(example.com/test)及其自己的htaccess文件。 看起來像這樣:

RewriteEngine On

RewriteRule ^(projects|about)/?$ /test/$1.php [L]
RewriteRule ^sitemap\.xml$ /test/xmlsitemap.php [L]

RewriteRule ^([^/]+)/?$ /test/projects.php?project=$1 [L] #this line causes trouble
RewriteRule ^([^/]+)/([0-9]+)/?$ /test/posts.php?&project=$1&post=$2 [L]
RewriteRule ^([^/]+)/([0-9]+)/([^/]+)/?$ /test/posts.php?project=$1&post=$2&title=$3 [L]

當我添加以下行: RewriteRule ^([^/]+)/?$ /test/projects.php?project=$1 [L]到我的.htaccess文件中時,測試目錄中的所有內容均顯示500 Internal Server Error 所有其他規則均按應有的方式工作。

我想做的是使example.com/test/$1轉到example.com/test/projects.php?project=$1 ,但“項目”,“關於”和“ sitemap.xml”除外“。 每個項目中也有編號的帖子,其URL的標題部分是可選的。

服務器正在運行apache 2.2.15。

如果您需要更多信息或希望我進行測試,請告訴我。

/test/文件夾中嘗試以下.htaccess:

RewriteEngine On
RewriteBase /test/

RewriteRule ^(projects|about)/?$ $1.php [L]
RewriteRule ^sitemap\.xml$ xmlsitemap.php [L]

# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/?$ projects.php?project=$1 [L,QSA]
RewriteRule ^([^/]+)/([0-9]+)/?$ posts.php?&project=$1&post=$2 [L,QSA]
RewriteRule ^([^/]+)/([0-9]+)/([^/]+)/?$ posts.php?project=$1&post=$2&title=$3 [L,QSA]

您現在制定的規則將導致以下結果:

http://example.com/test/1 -> http://example.com/test/posts.php?&project=test&post=1 

假設您沒有在訪問或錯誤日志中看到任何有用的信息,然后考慮將重寫日志條目添加到主機。

RewriteLog /var/log/httpd/rewrite.log
RewriteLogLevel 9

這可以幫助檢測類似重定向循環的事件,這可能是內部服務器錯誤的原因。

暫無
暫無

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

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