我有一个为客户编写和维护的网站。我目前在 1&1 上托管它。该网站在 3-4 周前运行良好。在那个时间范围内没有对其进行任何更改,客户只是注意到重定向不再起作用。
该站点已设置为将所有 url 重定向到 view.php 文件,然后使用 php include 语句将正确的页面加载到网站模板中。
有三个主要的测试用例:
http://www.hazardcontrol.com/factsheets/workplace/industrial-safety
应该重定向到:/view.php?fs=workplace&p=industrial-safety
http://www.hazardcontrol.com/library/topical-index
应该重定向到:/view.php?f=library&p=topical-index
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]