[英]htaccess url rewrites and redirects not working
我有一个已更新的网站。 我想使旧的url有效,我想重定向其中一些,因此来自Google搜索的链接仍然有效,并使用.htaccess重写其他url的URL。
例如:
另一个值得一提的是:该站点将每个请求发送到/index.php,因为这些URL并非针对物理文件,但是index.php脚本使用所请求的路径进行内部路由以提供正确的内容。
我不确定是否可以在同一htaccess中进行重写(服务->咨询),然后再进行重写(consultancy-> index.php)。
尝试此操作,对于任何URL,我都收到内部服务器错误500:
RewriteEngine On
#NEW
RewriteCond %{REQUEST_URI} ^services$ [NC]
RewriteRule ^services$ consultancy [L]
#LEGACY
RewriteRule (.*) ./index.php
还尝试了Redirect 301指令,但是没有运气,同样的错误500。
关于如何混合重写,重定向和最终重写到index.php的任何想法?
谢谢!
对于重定向和重写的组合,我意识到某些规则与我原来的问题有些不同,并且可能会引起问题,下面是一个示例:
# Redirect to show "consultancy" in the URL
RewriteRule ^services/a/b?$ consultancy [QSA,R,L,NC]
# If "consultancy" is in the URL, change it to the real path
# "consultancy" is an alias of the path that should be processed by index.php
RewriteRule ^consultancy/?$ en/consultoria [NC]
# Should get the "en/consultoria" path
RewriteRule ^ ./index.php [L]
上一个示例的问题在于,我获得了重定向“ services / a / b”->“ consultany”,但未完成重写“ consultancy”->“ en / consultoria”的操作。
有任何想法吗?
您可以使用:
RewriteEngine On
#rewrite
RewriteRule ^services/?$ consultancy [L,NC]
#redirect
RewriteRule ^services/a/b/?$ consultancy [L,NC,R=302]
#LEGACY
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.