簡體   English   中英

htaccess重寫多個參數的干凈URL

[英]htaccess rewrite clean url for multiple parameters

這是我的.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]

該代碼對於url單個參數正常工作。 例如,它rewrites

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

但是,當我嘗試在url傳遞多個參數時,我得到的只是errors

我需要一個網址
http://example.com/example-path而不是http://example.com/index.php?bank=example-path

如何更改我的代碼以傳遞多個URL。

您的重定向邏輯可以大大簡化為:

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