简体   繁体   English

htaccess重写多个参数的干净URL

[英]htaccess rewrite clean url for multiple parameters

This is my .htaccess code for clean url rewriting. 这是我的.htaccess代码,用于干净的URL重写。

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 . 该代码对于url单个参数正常工作。 For example it rewrites 例如,它rewrites

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

But when I tried to pass multiple parameters in url , all I got are errors . 但是,当我尝试在url传递多个参数时,我得到的只是errors

I need a url like 我需要一个网址
http://example.com/example-path instead of http://example.com/index.php?bank=example-path http://example.com/example-path而不是http://example.com/index.php?bank=example-path

How can I alter My code to pass multiple urls. 如何更改我的代码以传递多个URL。

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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