需要有关.htaccess代码的帮助才能将动态网址重定向到静态

时间:2015-05-02 07:17:30

标签: apache .htaccess mod-rewrite redirect

我是这个论坛的新成员,但很久以前就使用过这个网站了。这次我正在寻找.htaccess代码的自定义帮助,将我的网站网址重定向为静态网址。如果有人可以提供帮助,我将不胜感激 -

以下是当前的实时链接 -

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]

但它根本没有帮助我。

2 个答案:

答案 0 :(得分:0)

试试这个:

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

答案 1 :(得分:0)

这应该适合你:

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]