2013-01-18 47 views
1

我想在我的.htaccess幾個要素:的.htaccess 1個或2 GET參數

  • 我希望所有的PHP文件通過訪問/index,而不必把.php後,開始工作。

我使用:

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php 
  • 我有一個index.php頁,有時具有1個GET參數,有時2:

    • www.domain.com/?first=data
    • www.domain.com/?first=data &第二= DATA2

我用:

RewriteRule ^(.*)/(.*)$ index.php?id=$1&p=$2 
RewriteRule ^(.*)$ index.php?id=$1 [L] 

但是,如果我有2種元素它的唯一的工作;如果我用剛纔的第一個參數的鏈接,我得到一個錯誤頁面。

我該怎麼解決呢?

+0

#2,看看'[QSA]'。 http://httpd.apache.org/docs/current/mod/mod_rewrite.html – cmbuckley

回答

0

希望它能幫助:

Options +SymLinksIfOwnerMatch 

RewriteEngine on 

RewriteRule ^([a-zA-Z-]+)$ index.php?action=$1 [NC,L] 

RewriteRule ^(member)-([0-9-]+)$ index.php?action=member&id=$2 [NC,L] 

RewriteRule ^([a-zA-Z-]+)/([a-zA-Z-]+)-([0-9-]+)$ index.php?action=$1&saction=$2&sid=$3 [NC,L] 

RewriteRule ^([a-zA-Z-]+)/([0-9-]+)$ index.php?action=$1&id=$2 [NC,L] 

RewriteRule ^([0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/(.*).html$ index.php?action=details&id=$1&p1=$2&p2=$3&p3=$4 [NC,L]