1

I'm building an FAQ section. It will have separate sections

SECTION1 Q1 A1

Q2 A2

SECTION2 ...ETC.

I am trying to add some PHP logic that will work with .htaccess rewrite.

The page will have the following logic:

$faq_S = $_GET['section'];
$faq_Q = $_GET['q'];    

if (!isset($faq_C)) { 
  // show all sections
} else {
  // show only the section that's set

  if (!isset($faq_q)) { 
     // open the question
  } else {
     // show all questions in the section
  }
}

So, in order to be able to access the page without section and question values I have this:

RewriteRule ^faq|faq/$ pages/faq.inc.php [NC,L]

and I was hoping to add section and question as:

RewriteRule ^faq/([^/]+)/([^/]*)$ pages/faq.inc.php?cat=$1&q=$2 [NC,L]

But it seems that while the first rule works, the second does not. Also I think there might be a better way to have it combined in one. Is there?

4

1 回答 1

3

ReWriteRule您可以在.htaccess文件中使用以下内容将/faq/faq/value1和定向/faq/value1/value2到请求的页面设置catq

ReWriteRule ^faq/?([a-zA-Z0-9]+)?/?([a-zA-Z0-9]+)?/?$ pages/faq.inc.php?cat=$1&q=$2

当然,您可以更改[a-zA-Z0-9]为您喜欢的任何其他选择器...

编辑

澄清一下,这取代了您当前的两个规则

于 2013-07-13T19:51:31.877 回答