[英]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.