簡體   English   中英

我如何htaccess重定向和重寫index.php和參數到新的url,而無需更改鏈接或文件?

[英]How do I htaccess redirect and rewrite index.php & parameters to new url, without changing links or files?

如果我的網站網址為

/index.php?view=prod&id=11

(其中11可以是任何ID號)

如何將其重定向重寫為SEF鏈接,例如

/product/11/

這樣,轉到index.php ...鏈接的任何人都將始終重定向到SEF鏈接嗎?

到目前為止,我的解決方案是

RewriteRule    ^product/([0-9]+)/?$    index.php?view=prod&id=$1 [NC,L] 

但這根本不會重定向原始的index.php鏈接,盡管SEF鏈接由於某種原因起作用,但它不顯示任何CSS...。這很奇怪。

謝謝。

對於.htaccess ,請使用:

Options -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+index\.php\?view=prod&id=([^\s&]+) [NC]
RewriteRule ^ /product/%1/? [R=302,L,NE]

RewriteRule ^product/(\d+)/?$ index.php?view=prod&id=$1 [NC,L]

測試工作正常時,將[R=301] [R=302]更改為。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM