.htaccess有多个参数

时间:2013-06-24 11:49:32

标签: jquery .htaccess mod-rewrite

我有以下.htaccess-File:

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^([^/]*)/([^/]*)?$ index.php?parent=$1&page=$2 [L,QSA]
 RewriteRule ^([^/]*)/?$ index.php?page=$1 [L,QSA]
</IfModule>

它会将mypage.com/about之类的网址重新改写为mypage.com/index.php?page=about

当我致电mypage.com/work/project时,它应该将我与mypage.com/index.php?parent=work&page=project联系起来,但它不起作用 如果我直接致电mypage.com/index.php?parent=work&page=project,网站将毫无问题地加载。我可以回应GET参数,它们两者都是相同的。

使用这些GET参数,我加载了页面内容(jQuery):

<script type="text/javascript"> 
 $(document).ready(function() {
   var page = '<?php echo $page; ?>';
   var parent = '<?php echo $parent; ?>';
    if (page == "") {
     $("section").load("view/home.php article");
    } else {
     if (parent == "") {
      $("section").load("view/" + page + ".php article");
     } else {
      $("section").load("view/" + parent + "/" + page + ".php article");
     }
    }
   });
</script>

我错了什么?有人可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

将.htaccess更改为

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*?)/([^/]+?)/?$ index.php?parent=$1&page=$2 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/?$ index.php?page=$1 [L,QSA]

请注意,这会将mypage.com/work/重定向到mypage.com/index.php?page=work。如果您希望将+?重定向到*?,请将mypage.com/index.php?parent=work&page=更改为{{1}}。