0

我正在为 .htaccess 苦苦挣扎,我有以下代码:

<pre>
# PRODUCTS
RewriteRule ^(.*)/(.*)$     /newwebsite/product.php?category=$1&product=$2 [L,NC]

# SERVICES
RewriteRule ^(.*)/(.*)$     /newwebsite/service.php?category=$1&service=$2 [L,NC]

# PLAIN PAGES
RewriteRule ^/$                             /newwebsite/index.php  [L,NC]
RewriteRule ^signup-free$                   /newwebsite/signup-free.php  [L,NC]
RewriteRule ^about$                         /newwebsite/content.php?page=1 [L,NC]
RewriteRule ^portfolio$                     /newwebsite/portfolio.php [L,NC]
RewriteRule ^our-stores$                    /newwebsite/our-stores.php  [L,NC]
RewriteRule ^contact$                       /newwebsite/contact.php  [L,NC]
RewriteRule ^products-list$                 /newwebsite/lists.php?action=products  [L,NC]
RewriteRule ^services-list$                 /newwebsite/lists.php?action=services  [L,NC]
</pre>

我的代码无法正常工作,我需要在产品和服务规则中添加一些内容,以使它们分别重定向到“product.php”和“service.php”,而不再添加“斜杠”或“子文件夹”,但我没有'不知道什么和如何,我的意思是我只需要那个:

http://www.root.com/maintenance-services/weekly-pool-service  
  redirects to =>  
http://www.root.com/service.php?category=maintenance-services&service=weekly-pool-service

但同时我需要:

http://www.root.com/hot-tubs/jacuzzi 
  redirects to =>  
http://www.root.com/product.php?category=hot-tubs&product=jacuzzi

如何区分产品和服务,如何告诉 apache 使用相同的参数转到不同的页面?

我很困惑。非常感谢。

4

1 回答 1

2

制作文件rewrite.php,将所有内容重定向到那里:

RewriteRule ^(.*)/(.*)$     /newwebsite/rewrite.php?sub=$1&second=$2 [L,NC]

将所有逻辑放在这个文件中。

伪代码

if($_GET['sub'] exists in table "service") {
   $_GET['category'] = $_GET['sub'];
   $_GET['service'] = $_GET['second'];
   include 'service.php';
}else{
   ...
}
于 2013-01-03T11:42:43.673 回答