2013-01-18 105 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]