我在php.ini
文件中使用return string.matches(".*\\d+.*");
,如下所示:
Redirect
除了PDF文件的规则外,所有重定向都能正常工作。旧文件是:
.htaccess
而新的是:
## Redirects
Redirect 301 /d1_tm1_location.html /d1_tm1_location.php
Redirect 301 /d1_tm2_history.html /d1_tm2_history.php
Redirect 301 /d1_tm3_articles.html /d1_tm3_articles.php
Redirect 301 /d1_tm4_culture.html /d1_tm4_culture.php
Redirect 301 /d1_tm5_economy.html /d1_tm5_economy.php
Redirect 301 /d1_tm6_symbols.html /d1_tm6_symbols.php
Redirect 301 /d1_tm7_gallery.html /d1_tm6_symbols.php
Redirect 301 /d1_tm_civil.html /d1_tm6_symbols.php
Redirect 301 /d1_tm_education.html /d1_tm6_symbols.php
Redirect 301 /d1_tm_sport.html /d1_tm_sport.php
Redirect 301 /d1_tm_villages.html /d1_tm_villages.php
Redirect 301 /d2_ref1_phonebook.html /d2_ref1_phonebook.php
Redirect 301 /d2_ref_transport.html /d2_ref_transport.php
Redirect 301 /d3_ic1_services.html /d3_ic1_services.php
Redirect 301 /d3_ic_enterpreneur.html /d3_ic_enterpreneur.php
Redirect 301 /d3_ic_eservices.html /d3_ic_eservices.php
Redirect 301 /d3_ic_social.html /d3_ic_social.php
Redirect 301 /d3_ic_taxes.html /d3_ic_taxes.php
Redirect 301 /d4_adm1_structure.html /d4_adm1_structure.php
Redirect 301 /d4_adm2_contacts.html /d4_adm2_contacts.php
Redirect 301 /d4_adm5_strategy.html /d4_adm5_strategy.php
Redirect 301 /d4_adm6_budget.html /d4_adm6_budget.php
Redirect 301 /d4_adm7_registers.html /d4_adm7_registers.php
Redirect 301 /d4_adm_awards.html /d4_adm_awards.php
Redirect 301 /d5_mc1_composition.html /d5_mc1_composition.html
Redirect 301 /d5_mc2_regulations.html /d5_mc2_regulations.php
Redirect 301 /d6_prj1_current.html /d6_prj1_current.php
# >>> FAILS TO MATCH
Redirect 301 /adm_strategy/Strategia%20za%20zakrila%20na%20deteto%202007-2009.pdf /adm_strategy/Strategia%20za%20zakrila%20na%20deteto.pdf
RedirectMatch 301 /buyerprofile/(.*)\.html$ /buyerprofile/$1.php
http://www.lyaskovets.net/adm_strategy/Strategia%20za%20zakrila%20na%20deteto%202007-2009.pdf
位于http://www.lyaskovets.net/adm_strategy/Strategia%20za%20zakrila%20na%20deteto.pdf
文件中。
我不知道问题是否与该文件类型是PDF有关,或者文件名是否包含空格,但此规则不起作用。 有人可以帮助我找到解决问题的地方......
两台Apache服务器上的情况相同:
Linux: Apache / 2.2.3(CentOS)服务器,网址为www.lyaskovets.net端口80
Windows: Apache / 2.2.19(Win64)PHP / 5.3.5服务器,位于www1.lyaskovets.net端口80
答案 0 :(得分:2)
Redirect 301 /adm_strategy/Strategia%20za%20zakrila%20na%20deteto%202007-2009.pdf /adm_strategy/Strategia%20za%20zakrila%20na%20deteto.pdf
mod_alias Redirect
指令与%-decoded URL-path匹配。 (%20
只是原始请求中的URL编码空间。)
所以,这应该改写为:
Redirect 301 "/adm_strategy/Strategia za zakrila na deteto 2007-2009.pdf" "/adm_strategy/Strategia za zakrila na deteto.pdf"
用双引号括起参数,因为空格是Apache配置文件中的分隔符(即特殊字符)。
如果可以,最好避免使用文件名/网址中的空格。
参考:
https://httpd.apache.org/docs/current/mod/mod_alias.html#redirect