簡體   English   中英

htaccess / mod_rewrite停止工作—忽略重寫規則

[英]htaccess / mod_rewrite stopped working — ignoring rewrite rule

我有一個我為客戶編寫並維護的網站。 我目前在1&1上托管它。 該網站運行良好,直到3-4周前。 在那個時間范圍內,任何地方都沒有對其進行任何更改,客戶端只是注意到重定向不再起作用。

該站點已設置為將所有URL重定向到view.php文件,然后使用php include語句將正確的頁面加載到網站模板中。

有三個主要的測試用例:

  1. http://www.hazardcontrol.com/factsheets/workplace/industrial-safety應該重定向到: /view.php?fs=workplace&p=industrial-safety

  2. http://www.hazardcontrol.com/library/topical-index應該重定向到: /view.php?f=library&p=topical-index

  3. http://www.hazardcontrol.com/factsheets/pdfs/workplace-safety-programming.pdf不應重定向

當它第一次崩潰(加載了view.php頁面,但是找不到正確的內容頁面)時,我在view.php文件中使用了php echo語句來查找正在傳遞的GET變量。 一致地,無論嘗試了什么URL,它們最終都是f = reset:和p = view。

我嘗試編輯htaccess文件以對其進行更新,並確保所有內容都干凈,簡單且正確。 現在,情況1運行正常。 案例2在5分鍾前運行,但現在還沒有-嘗試重定向到視圖頁面。 情況3直接進入“ /library/topical-index.php”頁面,該頁面實際保存內容,而不是重定向到view.php頁面,以便將其加載到模板中。 這兩個htaccess文件都在下面。

預先感謝您提供的任何幫助!

原始htaccess文件

(這確實起作用。我確實嘗試調用1&1,但是他們向我保證,除了一個月前更新Apache之外,他們什么都沒做,但這是在我的網站崩潰之前,所以必須是我的腳本)。

注意:最后8個重寫器是相關的。

RewriteEngine on
RewriteBase /

#Exceptions to rewrite rules
RewriteRule ^(phaseout)($|/) - [L]

#Control user navigation quirks (like just deleting parts of the link)
redirect 301 /index.htm http://www.hazardcontrol.com
redirect 301 /default.htm http://www.hazardcontrol.com
redirect 301 /default.html http://www.hazardcontrol.com

RewriteCond %{HTTP_HOST} !^www\.hazardcontrol\.com
RewriteRule (.*) http://www.hazardcontrol.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^.*/index\.html
RewriteRule ^(.*)index.html$ http://www.hazardcontrol.com/$1 [R=301,L]

#Ensure the website is always addressed as www.hazardcontrol.com
RewriteCond %{HTTP_HOST} ^hazardcontrol\.com$ [NC]
RewriteRule ^(.*)$ http://www.hazardcontrol.com/$1 [R=301,L]

ErrorDocument 404 /sitemanagement/404
ErrorDocument 403 /sitemanagement/403

redirect 301 /coreprinciples.html http://www.hazardcontrol.com/factsheets/principles/core-principles
redirect 301 /emailus.html http://www.hazardcontrol.com/about/contact-us
redirect 301 /agricultural.html http://www.hazardcontrol.com/factsheets/workplace/agricultural-safety
redirect 301 /BuildingCode.html http://www.hazardcontrol.com
redirect 301 /construction.html http://www.hazardcontrol.com/factsheets/workplace/construction-safety
redirect 301 /consultants.html http://www.hazardcontrol.com/about/about
redirect 301 /copyright.html http://www.hazardcontrol.com/copyright/copyright
redirect 301 /craneandhoist.html http://www.hazardcontrol.com/factsheets/workplace/construction-safety
redirect 301 /fallprevention.html http://www.hazardcontrol.com/factsheets/falls/design-of-fall-protection-systems
redirect 301 /gnelson.html http://www.hazardcontrol.com/about/bio
redirect 301 /humanfactors.html http://www.hazardcontrol.com/factsheets/humanfactors/human-factors-and-ergonomics
redirect 301 /index.htm http://www.hazardcontrol.com
redirect 301 /jenglish.html http://www.hazardcontrol.com/about/about
redirect 301 /jobs.html http://www.hazardcontrol.com
redirect 301 /lifting.html http://www.hazardcontrol.com/factsheets/ml-mh/landmark-manual-lifting-standards
redirect 301 /links.html http://www.hazardcontrol.com
redirect 301 /machineguarding.html http://www.hazardcontrol.com/factsheets/machineguarding/history-of-machine-guarding
redirect 301 /marine.html http://www.hazardcontrol.com/factsheets/workplace/marine-offshore-safety
redirect 301 /missing.html http://www.hazardcontrol.com
redirect 301 /ml-design.html http://www.hazardcontrol.com/factsheets/ml-mh/NIOSH-guidelines-and-revised-formula
redirect 301 /ml-historical http://www.hazardcontrol.com/factsheets/ml-mh/evolution-of-manual-lifting-standards
redirect 301 /ml-niosh81.html http://www.hazardcontrol.com/factsheets/ml-mh/NIOSH-guidelines-and-revised-formula
redirect 301 /ml-niosh93.html http://www.hazardcontrol.com/factsheets/ml-mh/NIOSH-guidelines-and-revised-formula
redirect 301 /ml-training.html http://www.hazardcontrol.com/main_page.php?folder=fs_workplace_safety&page=workplace_safety_training
redirect 301 /oilfield.html http://www.hazardcontrol.com/factsheets/workplace/construction_safety
redirect 301 /premises.html http://www.hazardcontrol.com/factsheets/premises/five-types-of-same-level-falls
redirect 301 /product.html http://www.hazardcontrol.com/factsheets/product/basic-elements-of-product-safety-programming
redirect 301 /rampfalls.html http://www.hazardcontrol.com/factsheets/premises/ramp-design-analysis
redirect 301 /slipandfall.html http://www.hazardcontrol.com/factsheets/falls/design-of-fall-protection-systems
redirect 301 /sliptrip.html http://www.hazardcontrol.com/factsheets/premises/five-types-of-same-level-falls
redirect 301 /stairramp.html http://www.hazardcontrol.com/factsheets/premises/design-of-fall-protection-systems
redirect 301 /stairwayfalls.html http://www.hazardcontrol.com/factsheets/premises/stairway-design-analysis
redirect 301 /trial.html http://www.hazardcontrol.com
redirect 301 /tripandfall.html http://www.hazardcontrol.com/factsheets/premises/five-types-of-same-level-falls
redirect 301 /vehiclefalls.html http://www.hazardcontrol.com/factsheets/falls/access-to-vehicles
redirect 301 /workplace.html http://www.hazardcontrol.com/factsheets/workplace/industrial-safety

#Rewrite dynamic URIs as static/flat URIs for user ease and search engine happiness
RewriteRule ^factsheets/([^/\.]+)/([^/.]+)$ view.php?fs=$1&p=$2 [L]
RewriteRule ^factsheets/([^/.]+)/([^/.]+).php$ view.php?fs=$1&p=$2 [L]
RewriteRule ^factsheets/([^/.]+)/([^/.]+).htm$ view.php?fs=$1&p=$2 [L]
RewriteRule ^factsheets/([^/.]+)/([^/.]+).html$ view.php?fs=$1&p=$2 [L]

RewriteRule ^([^/.]+)/([^/.]+)$ view.php?f=$1&p=$2 [L]
RewriteRule ^([^/.]+)/([^/.]+).php$ view.php?f=$1&p=$2 [L]
RewriteRule ^([^/.]+)/([^/.]+).htm$ view.php?f=$1&p=$2 [L]
RewriteRule ^([^/.]+)/([^/.]+).html$ view.php?f=$1&p=$2 [L] 

新的htaccess文件

注意:最后3個重寫器是相關的。

RewriteEngine on
RewriteBase /

#Exceptions to rewrite rules
RewriteRule ^(phaseout)($|/) - [L]

#Control user navigation quirks (like just deleting parts of the link)
redirect 301 /index.htm http://www.hazardcontrol.com
redirect 301 /default.htm http://www.hazardcontrol.com
redirect 301 /default.html http://www.hazardcontrol.com

# -> Prevent users from accessing another domain name
RewriteCond %{HTTP_HOST} !^www\.hazardcontrol\.com
RewriteRule (.*) http://www.hazardcontrol.com/$1 [R=301,N]

# -> Prevent users from trying to access the 'index page' of a folder or section
RewriteCond %{THE_REQUEST} ^.*/index\.html
RewriteRule ^(.*)index.html$ http://www.hazardcontrol.com/$1 [R=301,N]

# -> Ensure the website is always addressed as www.hazardcontrol.com
RewriteCond %{HTTP_HOST} ^hazardcontrol\.com$ [NC]
RewriteRule ^(.*)$ http://www.hazardcontrol.com/$1 [R=301,N]

#Custom error docs
ErrorDocument 404 /sitemanagement/404
ErrorDocument 403 /sitemanagement/403

#Maintain legacy search engine page ranks by redirecting them to our new pages
redirect 301 /coreprinciples.html http://www.hazardcontrol.com/factsheets/principles/core-principles
redirect 301 /emailus.html http://www.hazardcontrol.com/about/contact-us
redirect 301 /agricultural.html http://www.hazardcontrol.com/factsheets/workplace/agricultural-safety
redirect 301 /BuildingCode.html http://www.hazardcontrol.com
redirect 301 /construction.html http://www.hazardcontrol.com/factsheets/workplace/construction-safety
redirect 301 /consultants.html http://www.hazardcontrol.com/about/about
redirect 301 /copyright.html http://www.hazardcontrol.com/copyright/copyright
redirect 301 /craneandhoist.html http://www.hazardcontrol.com/factsheets/workplace/construction-safety
redirect 301 /fallprevention.html http://www.hazardcontrol.com/factsheets/falls/design-of-fall-protection-systems
redirect 301 /gnelson.html http://www.hazardcontrol.com/about/bio
redirect 301 /humanfactors.html http://www.hazardcontrol.com/factsheets/humanfactors/human-factors-and-ergonomics
redirect 301 /index.htm http://www.hazardcontrol.com
redirect 301 /jenglish.html http://www.hazardcontrol.com/about/about
redirect 301 /jobs.html http://www.hazardcontrol.com
redirect 301 /lifting.html http://www.hazardcontrol.com/factsheets/ml-mh/landmark-manual-lifting-standards
redirect 301 /links.html http://www.hazardcontrol.com
redirect 301 /machineguarding.html http://www.hazardcontrol.com/factsheets/machineguarding/history-of-machine-guarding
redirect 301 /marine.html http://www.hazardcontrol.com/factsheets/workplace/marine-offshore-safety
redirect 301 /missing.html http://www.hazardcontrol.com
redirect 301 /ml-design.html http://www.hazardcontrol.com/factsheets/ml-mh/NIOSH-guidelines-and-revised-formula
redirect 301 /ml-historical http://www.hazardcontrol.com/factsheets/ml-mh/evolution-of-manual-lifting-standards
redirect 301 /ml-niosh81.html http://www.hazardcontrol.com/factsheets/ml-mh/NIOSH-guidelines-and-revised-formula
redirect 301 /ml-niosh93.html http://www.hazardcontrol.com/factsheets/ml-mh/NIOSH-guidelines-and-revised-formula
redirect 301 /ml-training.html http://www.hazardcontrol.com/main_page.php?folder=fs_workplace_safety&page=workplace_safety_training
redirect 301 /oilfield.html http://www.hazardcontrol.com/factsheets/workplace/construction_safety
redirect 301 /premises.html http://www.hazardcontrol.com/factsheets/premises/five-types-of-same-level-falls
redirect 301 /product.html http://www.hazardcontrol.com/factsheets/product/basic-elements-of-product-safety-programming
redirect 301 /rampfalls.html http://www.hazardcontrol.com/factsheets/premises/ramp-design-analysis
redirect 301 /slipandfall.html http://www.hazardcontrol.com/factsheets/falls/design-of-fall-protection-systems
redirect 301 /sliptrip.html http://www.hazardcontrol.com/factsheets/premises/five-types-of-same-level-falls
redirect 301 /stairramp.html http://www.hazardcontrol.com/factsheets/premises/design-of-fall-protection-systems
redirect 301 /stairwayfalls.html http://www.hazardcontrol.com/factsheets/premises/stairway-design-analysis
redirect 301 /trial.html http://www.hazardcontrol.com
redirect 301 /tripandfall.html http://www.hazardcontrol.com/factsheets/premises/five-types-of-same-level-falls
redirect 301 /vehiclefalls.html http://www.hazardcontrol.com/factsheets/falls/access-to-vehicles
redirect 301 /workplace.html http://www.hazardcontrol.com/factsheets/workplace/industrial-safety

#Rewrite dynamic URIs as static/flat URIs for user ease and search engine happiness
RewriteRule ^(\.pdf)$ - [L]
RewriteRule ^factsheets/([^/\.]+)/([^/\.]+)(.*)$ view.php?fs=$1&p=$2 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)(.*)$ view.php?f=$1&p=$2 [L] 

為了使所有三種情況都起作用,我改變了

RewriteRule ^(\.pdf)$ - [L]

RewriteRule ^(.*\.pdf)$ $1 [L]

並且PDF沒有重定向。 之所以起作用,是因為正則表達式^(.*\\.pdf)$factsheets/pdfs/workplace-safety-programming.pdf相匹配。

為了排除故障,我使用了http://htaccess.madewithlove.be/

暫無
暫無

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

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