2013-02-23 75 views
1

我有一個非常簡單的重寫規則。我想在URL的第二個參數是可選的,但因爲它代表的那一刻我必須將它傳遞的網址:htaccess可選參數

RewriteEngine On 
RewriteRule ^signup/([^/]*)/([^/]*)/$ /signup/index.php?e=$1&s=$2 [L] 

我的網址/註冊/參數/可選參數/

如何讓網址工作,如果我離開第二個參數關閉?

+1

對於一個很好的例子在 http://stackoverflow.com/questions張貼在stackoverflow.com/11617183/htacess-和雙柱參數 – aeshabana 2013-02-23 19:49:18

回答

1

後,只需添加一個參數改寫:

RewriteEngine On 
RewriteRule ^signup/([^/]*)/([^/]*)/$ /signup/index.php?e=$1&s=$2 [L] 

# single parameter 
RewriteRule ^signup/([^/]*)/$ /signup/index.php?e=$1 [L] 
0

我使用的回答這個問題htacess and two post parameters ....感謝aeshabana的小費!

我還需要一個斜線添加到URL,這樣這裏是我最後的.htaccess

RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !(.*)/$ 
RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301] 

RewriteRule %{REQUEST_FILENAME} !-d 
RewriteRule %{REQUEST_FILENAME} !-f 
RewriteRule ^signup/(.+)/$ /signup/index.php?uri=$1 [QSA,L]