我已閱讀了有關此主題的多個主題,但他們都處理多個參數,並且我是相當新的與.htaccess我無法弄清楚如何修改答案以適應我需要的東西。.htaccess重寫php分頁
我使用.htaccess重寫網址,除了當我嘗試重寫分頁URL時,一切似乎都進行得很順利。
我的分頁網址非常簡單:blog.php?page = 2,但由於某些原因,我無法將網址重寫爲/ blog/page/2。當我嘗試將其路由到該URL時,出現「內部服務器錯誤」。現在我已將它改寫爲/ blog-page/2這沒關係,但我更願意擁有它/ blog/page/2。
我有很多我的.htaccess文件回事,所以我將只發布重寫:
RewriteEngine On
# Full path
#RewriteBase/
# Rewrite all php files
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
# Rewrite the user profile pages
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^user/([a-zA-Z0-9_-]+)$ profile.php?user=$1
RewriteRule ^user/([a-zA-Z0-9_-]+)/$ profile.php?user=$1
# Rewrite the company profile pages
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^company/([a-zA-Z0-9_-]+)$ employer.php?user=$1
RewriteRule ^company/([a-zA-Z0-9_-]+)/$ employer.php?user=$1
# Rewrite the blog post pages
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^post/([a-zA-Z0-9_-]+)$ entry.php?id=$1
RewriteRule ^post/([a-zA-Z0-9_-]+)/$ entry.php?id=$1
# Rewrite the job listing pages
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^job/([a-zA-Z0-9_-]+)$ listing.php?id=$1
RewriteRule ^job/([a-zA-Z0-9_-]+)/$ listing.php?id=$1
# Rewrite blog pagination
RewriteRule ^blog/page/([0-9]+)$ blog.php?page=$1
RewriteRule ^blog/page/([0-9]+)/$ blog.php?page=$1
很顯然,我遇到的問題是與最後重寫規則對博客的分頁。爲什麼我不能做到/ blog/page/2,但是我可以做到/ blog-page/2?
我也試圖做一個多頁.htaccess重寫博客類別和工作類別,但我不斷收到一個內部錯誤。我想爲博客重寫1個工作類別和博客類別。這是我有什麼:
# Rewrite the category queries
RewriteRule ^/category/(.*)/?$ /$.php?cat=$1 [L,QSA]
是否有可能使此分頁重寫工作的2個不同的頁面?比如blogs.php和jobs.php?
另外,是否有必要在制定重寫規則之前繼續使用RewriteCond %{REQUEST_FILENAME} !-f
?還是一次足夠?
在重寫規則RewriteRule^blog/page /([0-9] +)之前,嘗試將此行添加到最後一個規則集:'RewriteCond%{REQUEST_URI}!blog \ .php [NC] )$ blog.php?page = $ 1'等。 –
沒有工作,但這是一個好主意。我仍然收到「內部服務器錯誤」 –
您是否嘗試刪除該規則集以查看錯誤是否持續? –