簡體   English   中英

需要有關.htaccess代碼的幫助,以將動態URL重定向到靜態

[英]Need Help on .htaccess code to redirect dynamic URL into static

我是這個論壇的新成員,但是早就使用了這個網站。 這次,我正在尋找有關.htaccess代碼的自定義幫助,以將我的網站URL重定向到靜態URL。 如果有人可以提供幫助,我將不勝感激–

以下是當前的實時鏈接-

http://sitename.in/categories.php?category=chocolate-special&parent_id=12067

所有類別都一樣

我想將其轉換為

http://sitename.in/chocolate-special/12067

目前,我正在使用–

RewriteRule ^products/([a-zA-Z0-9-_%/,]+)/([a-zA-Z0-9-_%/,]+)/?$ categories.php?category=$1&parent_id=$2 [L,QSA]
RewriteCond %{THE_REQUEST} /categories\.php\?category=([^\s&]+)&parent_id=([^\s&]+) [NC]
RewriteRule ^ products/%1/%2? [R=301,L]

但這根本沒有幫助我。

嘗試這個:

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /categories.php?category=$1&parent_id=$2 [L,R=301]

這應該為您工作:

RewriteEngine On

# Rewrite products/*/* to categories.php, and send a dummy/useless parameter (r=1)

RewriteRule ^products/([a-zA-Z0-9-_%/,]+)/([a-zA-Z0-9-_%/,]+)/?$ categories.php?category=$1&parent_id=$2&r=1 [NC,QSA,L]

# Check access to the old URL, and redirect to the new URL
# Leave the dummy parameter (r=1) out of this so that there is no endless loop

RewriteCond %{QUERY_STRING} ^category=([^\s&]+)&parent_id=([\d]+)$ [NC]
RewriteRule ^categories.php /products/%1/%2? [R=301,L]

擴展:(用於注釋中的新請求)

RewriteEngine On

# Rewrite products/*/* to categories.php, and send a dummy/useless parameter (r=1)
RewriteRule ^products/([a-z0-9-_%/,]+)/([a-z0-9-_%/,]+)/?$ categories.php?category=$1&parent_id=$2&r=1 [NC,QSA,L]

# Rewrite auction-details/*/* to auction_details.php, and send a dummy/useless parameter (r=1)
RewriteRule ^auction-details/([a-z0-9-_%/,]+)/([\d]+)/?$ auction_details.php?name=$1&id=$2&r=1 [NC,QSA,L]

# Check access to the old URLs, and redirect to the new URLs
# Leave the dummy parameter (r=1) out of this so that there is no endless loop

# categories.php
RewriteCond %{QUERY_STRING} ^category=([^\s&]+)&parent_id=([\d]+)$ [NC]
RewriteRule ^categories.php /products/%1/%2? [R=301,L]

# auction_details.php
RewriteCond %{QUERY_STRING} ^name=([^\s&]+)&id=([\d]+)$ [NC]
RewriteRule ^auction_details.php /auction-details/%1/%2? [R=301,L]

暫無
暫無

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

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