【问题标题】:php:Mod rewrite giving me hard times finding base address.. need helpphp:Mod 重写让我很难找到基地址.. 需要帮助
【发布时间】:2011-07-01 02:27:12
【问题描述】:

我是 Mod_rewrite 的新手,但问题是它破坏了我所有的 ajax 和 php

我使用 windows.location 对象来获取 javascript 示例的当前位置:

var str = location.pathname;
str=str.slice(0,str.lastIndexOf('/'));

自从我使用了 mod_rewrite 以来,这永远不会奏效。 我的.htaccess

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^cars/([^/]+)/?$ profiles.php?carname=$1 [L]

可以让我找到解决此问题的方法吗? ? 我在装载所有 imgs 和 css/.js 时也面临同样的问题,但我听说我可以在 .htaccess 上写条件以仅重定向 .php!,

我需要一种方法来查找 ajax 调用的基地址,以及其他方法来查找 php 的基地址。

【问题讨论】:

    标签: php javascript mod-rewrite base-address


    【解决方案1】:

    问题是您将所有 url 重定向到一个 php 文件,它破坏了所有其他资产,包括 css 和 js。

    解决方案:

    使用重写条件。这样它只会在文件或目录不存在时重定向。

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^cars/([^/]+)/?$ profiles.php?carname=$1 [L]
    

    第一行是:如果文件不存在 第二个是:如果目录不存在 会有一个重定向。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多