search

Home  >  Q&A  >  body text

Unable to use htaccess multiple query strings properly

I want to get this URL:

example.com/scooter-details/1/vespa-sprint

But the URL I get is:

example.com/scooter-details.php?scooter_id=1&scooter_brand=vespasprint&scooter_model=

scooter_model "sprint" is in the scooter_brand query, which usually must be scooter_brand=vespa&scooter_model=sprint. Hope you can help me solve this problem

This is htaccess code

Options +FollowSymLinks -MultiViews
RewriteEngine On
# SEO FRIENDLY URL

# Redirect "/scooter-details.php?service_id=<num>" to "/scooter-details/<num>"
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^scooter_id=(\d+)&scooter_brand=([^/.]+)&scooter_model=([^/.]+)$
RewriteRule ^(scooter-details)\.php$ //%1/%2-%3? [QSD,L,R=301,N]

# Rewrite "/scooter-details/<num>" back to "scooter-details.php?service_id=<num>"
RewriteRule ^(scooter-details)/(\d+)/([^/]+)$ .php?scooter_id=&scooter_brand=&scooter_model= [L]

P粉312631645P粉312631645239 days ago475

reply all(1)I'll reply

  • P粉320361201

    P粉3203612012024-04-01 10:29:38

    If you want to capture elements of the query string (i.e. already URL encoded) and use them to build a URL path. Otherwise, you'll end up with the double URL-encoded portion of the resulting URL path - that's what it looks like.

    %20 is a double URL encoded space. ie. It appears that the query string you are capturing has (i.e. spaces) in it.

    However, the rule you posted seems to have nothing to do with the example URL given?

    reply
    0
  • Cancelreply