【问题标题】:apache rewrite rule modify url if not exitsapache重写规则如果不存在则修改url
【发布时间】:2013-12-30 14:46:06
【问题描述】:

我想为闲置用例编写 apache 重写规则。

我的用例是如果 url 不存在修改 url。

e.x

http://localhost/sign 不存在重定向到http://localhost/index.php/sign

如果http://localhost/images/dummy.jpg 存在,则什么也不做。

即如果 url 存在,则不做任何其他修改 url 并在域名后添加 index.php 并由请求的 uri 休耕。

任何人都可以帮助我实现这一目标。

【问题讨论】:

标签: php apache .htaccess mod-rewrite


【解决方案1】:

您可以在 DOCUMENT_ROOT/.htaccess 文件中使用此规则:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php/$1 [L,R]

【讨论】:

    【解决方案2】:
    ErrorDocument 404 /sign
    

    ErrorDocument Directive

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-15
      • 1970-01-01
      相关资源
      最近更新 更多