简体   繁体   English

htaccess / mod_rewrite停止工作—忽略重写规则

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

I have a website that I wrote and maintain for a client. 我有一个我为客户编写并维护的网站。 I am currently hosting it on 1&1. 我目前在1&1上托管它。 The website was working perfectly up until 3-4 weeks ago. 该网站运行良好,直到3-4周前。 No changes were made to it anywhere in that time frame, the client just noticed that the redirects were no longer working. 在那个时间范围内,任何地方都没有对其进行任何更改,客户端只是注意到重定向不再起作用。

The site is set up so that all urls are redirected to a view.php file, which then loads the correct page into the website template using a php include statement. 该站点已设置为将所有URL重定向到view.php文件,然后使用php include语句将正确的页面加载到网站模板中。

There are three main test cases: 有三个主要的测试用例:

  1. http://www.hazardcontrol.com/factsheets/workplace/industrial-safety should redirect to: /view.php?fs=workplace&p=industrial-safety http://www.hazardcontrol.com/factsheets/workplace/industrial-safety应该重定向到: /view.php?fs=workplace&p=industrial-safety

  2. http://www.hazardcontrol.com/library/topical-index should redirect to: /view.php?f=library&p=topical-index 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 should NOT redirect http://www.hazardcontrol.com/factsheets/pdfs/workplace-safety-programming.pdf不应重定向

When it first broke (loaded the view.php page, but can't find the correct content page to include), I used a php echo statement in the view.php file to find out what the GET variables were that were being passed. 当它第一次崩溃(加载了view.php页面,但是找不到正确的内容页面)时,我在view.php文件中使用了php echo语句来查找正在传递的GET变量。 Consistently they turned out to be f=reset: and p=view, no matter what url was tried. 一致地,无论尝试了什么URL,它们最终都是f = reset:和p = view。

I tried editing the htaccess file to update it and make sure everything was clean, simple, and correct. 我尝试编辑htaccess文件以对其进行更新,并确保所有内容都干净,简单且正确。 Now, case 1 is working fine. 现在,情况1运行正常。 Case 2 was working 5 minutes ago, but isn't now - it tries to redirect to the view page. 案例2在5分钟前运行,但现在还没有-尝试重定向到视图页面。 Case 3 is going straight to the '/library/topical-index.php' page that actually holds the content instead of redirecting to the view.php page so that it loads inside the template. 情况3直接进入“ /library/topical-index.php”页面,该页面实际保存内容,而不是重定向到view.php页面,以便将其加载到模板中。 Both htaccess files are below. 这两个htaccess文件都在下面。

Thanks in advance for any help you can provide! 预先感谢您提供的任何帮助!

Original htaccess file 原始htaccess文件

(which WAS working. I did try calling 1&1, but they assured me they hadn't done anything except update Apache a little over a month ago, but that was before my site broke so it MUST be my script). (这确实起作用。我确实尝试调用1&1,但是他们向我保证,除了一个月前更新Apache之外,他们什么都没做,但这是在我的网站崩溃之前,所以必须是我的脚本)。

NOTE: last 8 rewriterules are the relevant ones. 注意:最后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] 

New htaccess file 新的htaccess文件

NOTE: Last 3 rewriterules are the relevant ones. 注意:最后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] 

To get all three cases working, I changed 为了使所有三种情况都起作用,我改变了

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

to

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

and the PDF did not redirect. 并且PDF没有重定向。 This worked because the regular expression ^(.*\\.pdf)$ matched factsheets/pdfs/workplace-safety-programming.pdf . 之所以起作用,是因为正则表达式^(.*\\.pdf)$factsheets/pdfs/workplace-safety-programming.pdf相匹配。

To troubleshoot I used http://htaccess.madewithlove.be/ . 为了排除故障,我使用了http://htaccess.madewithlove.be/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM