dongyingdao8867 2015-04-20 10:06
浏览 23
已采纳

htaccess在jquery加载时递归加载

I have two URLs:

http://www.domain.com/catalogo
http://www.domain.com/catalogo/item1

My .htaccess header looks like this currently:

<IfModule mod_rewrite.c>
    Options +FollowSymLinks -Indexes -Multiviews
    RewriteEngine On

    RewriteBase /

    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
    RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f 

    RewriteRule ^inicio$ index.php [L]
    RewriteRule ^catalogo$ catalogo.php [L]
    RewriteRule ^catalogo/(.+) catalogo.php/$1 [L]
    RewriteRule ^empresa$ empresa.php [L]
    RewriteRule ^contacto$ contacto.php [L]
</IfModule> 

I load content into catalogo.php this way:

$("#contenido_catalogo").load("ajax_catalogo.php", {slu: 'lets_say_item1'}, function(){});

The first URL is loaded successfuly, but appending /item1 to the URL makes catalogo.php load recursively instead of ajax_catalogo.php.

It seems that loading of ajax_catalogo.php matches the second RewriteRule and creates the endless loop, but I have no idea how to avoid it.

How should I do it instead? Thank you.

  • 写回答

1条回答 默认 最新

  • doujia6433 2015-04-20 10:40
    关注

    First, adding [L] flag after each rule would be definitely good for you.
    Then, either define a RewriteBase or use absolute paths in your rules.
    Finally, disabling MultiViews option is also a good idea in your case.

    You can put this code in your htaccess (which has to be in root folder)

    Options -MultiViews
    
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^catalogo$ catalogo.php [L]
    RewriteRule ^catalogo/(.+)$ catalogo.php/$1 [L]
    

    Note: no need to worry about the order of your 2 rules in this case (they don't interfere)


    EDIT:

    <IfModule mod_rewrite.c>
        Options +FollowSymLinks -Indexes -Multiviews
    
        RewriteEngine On
        RewriteBase /
    
        RewriteCond %{HTTPS} !=on
        RewriteCond %{HTTP_HOST} !^www\. [NC]
        RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    
        RewriteCond %{REQUEST_FILENAME} -d [OR]
        RewriteCond %{REQUEST_FILENAME} -f 
        RewriteRule ^ - [L]
    
        RewriteRule ^inicio$ index.php [L]
        RewriteRule ^catalogo$ catalogo.php [L]
        RewriteRule ^catalogo/(.+)$ catalogo.php/$1 [L]
        RewriteRule ^empresa$ empresa.php [L]
        RewriteRule ^contacto$ contacto.php [L]
    </IfModule> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块