dptx8888 2013-01-03 11:36
浏览 70
已采纳

如何写一个'root'RewriteRule重定向到两个不同的页面?

I am struggling with .htaccess, I have this code:

<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>

My code is not working properly, I need to add something to Products and Services rules to make them redirect to 'product.php' and 'service.php' respectively, without adding no more 'slash' or 'subfolder', but I don't know what and how, I mean I just need that:

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

but at the same time I need that:

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

How can I make a difference between PRODUCTS and SERVICES, how can I tell apache to go to different pages with the same parameters?

I am confused. Thank you very much.

  • 写回答

1条回答 默认 最新

  • doucuan5365 2013-01-03 11:42
    关注

    Make file rewrite.php, redirect everything there:

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

    Put all logic in this file.

    Pseudo code

    if($_GET['sub'] exists in table "service") {
       $_GET['category'] = $_GET['sub'];
       $_GET['service'] = $_GET['second'];
       include 'service.php';
    }else{
       ...
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 怎样才能让鼠标沿着线条的中心线轨迹移动
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?