简体   繁体   中英

htaccess rewrite clean url for multiple parameters

This is my .htaccess code for clean url rewriting.

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[a-zA-Z]{3,}\s/+index\.php\?bank=([^\s&]+) [NC]
RewriteRule ^ %1%2%3%4? [R=301,L]
RewriteRule ^([^/]+)/?$ index.php?bank=$1$2$3$4 [L,QSA]

This code works fine for single parameter in url . For example it rewrites

http://example.com/example-path/ to
http://example.com/index.php?bank=example-path/

But when I tried to pass multiple parameters in url , all I got are errors .

I need a url like
http://example.com/example-path instead of http://example.com/index.php?bank=example-path

How can I alter My code to pass multiple urls.

Your redirect logic can be greatly simplified to just:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

#If a request does not match an existing directory
  RewriteCond %{REQUEST_FILENAME} !-d
#And does not match an existing file
  RewriteCond %{REQUEST_FILENAME} !-f
#then rewrite all requests to index.php
  RewriteRule ^(.*)/?$ index.php?bank=$1 [L,QSA]

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