简体   繁体   中英

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

I am new member at this forum but using this site since long back. This time I am looking for custom help on .htaccess code to redirect my website URLs into static one. I will appreciate if someone can help on this –

Below is current live link -

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

Same is going in all categories

I want to convert it into

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

Currently I am using –

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]

But it's not helping me at all.

Try this:

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

This should work for you:

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]

Extended: (for new request in comments)

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM