我有一个我为客户编写和维护的网站。我目前正在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变量是什么被通过。他们一直都是f = reset:而p = view,无论尝试了什么网址。
我尝试编辑htaccess文件来更新它,并确保一切都干净,简单,正确。现在,案例1工作正常。案例2在5分钟前工作,但现在不是 - 它试图重定向到视图页面。案例3直接进入'/library/topical-index.php'页面,该页面实际上保存内容而不是重定向到view.php页面,以便它加载到模板中。两个htaccess文件都在下面。
提前感谢您提供的任何帮助!
原始htaccess文件
(WAS正在工作。我确实试过调用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]
答案 0 :(得分:0)
为了让所有三个案例都有效,我改变了
RewriteRule ^(\.pdf)$ - [L]
到
RewriteRule ^(.*\.pdf)$ $1 [L]
并且PDF没有重定向。这很有效,因为正则表达式^(.*\.pdf)$
与factsheets/pdfs/workplace-safety-programming.pdf
匹配。
要解决问题,我使用了http://htaccess.madewithlove.be/。