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