繁体   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