【问题标题】:.htaccess - load index.php when no specific word otherwise other file.htaccess - 在没有特定单词时加载 index.php,否则加载其他文件
【发布时间】:2020-05-07 08:37:06
【问题描述】:

我想默认加载index.php BUT,如果url中有callcall.php,它应该加载call.php文件: p>

默认网址(以下网址应加载 ROOT/index.php):

http://example.com/rgt-cfjv-vlm
http://example.com/index.php/rgt-cfjv-vlm

其他网址(以下网址应加载 ROOT/call.php):

http://example.com/call/rgt-cfjv-vlm
http://example.com/call.php/rgt-cfjv-vlm

注意“rgt-cfjv-vlm”是一个随机字符串,它总是会出现在 URL 中

任何帮助将不胜感激!谢谢。

【问题讨论】:

  • apache 别名(别名“/call”,后跟 Directory,您可以在其中将 DirectoryIndex 作为 call.php )也可以使用
  • @TranquillityI don't have access to apache setting bro

标签: php apache .htaccess mod-rewrite url-rewriting


【解决方案1】:

给你:

RewriteEngine on

RewriteCond %{REQUEST_URI} call
RewriteRule .* call.php 

RewriteCond %{REQUEST_URI} !call
RewriteRule .* index.php 

【讨论】:

  • 使用这个 htaccess,它的加载 call.php 总是带有两个 url。即http://example.com/rgt-cfjv-vlm and http://example.com/index.php/rgt-cfjv-vlm
  • 不应该。有没有加“!”在第二种情况。第一个条件是如果 URL 包含调用则加载 call.php 第二个条件是如果它不包含则调用 index.php。我已经测试过了。您的 htaccess 中还有其他重定向吗?
  • 我正在使用您提供的 .htaccess。不,我的 .htaccess 中没有额外的代码,但无论如何它仍然加载 call.php
  • [链接]htaccess.madewithlove.be 。将我的 htaccess 复制到此处并写下您的 url 以进行测试:example.com/index.php/rgt-cfjv-vlmexample.com/call/rgt-cfjv-vlm 或其他任何内容。
  • .htaccess Shareable URL 请检查,它的 localhost 可通过 ngrok 共享 url
【解决方案2】:

解决方法: 我已将目录结构更改如下:

对于默认 URL (http://example.com/rgt-cfjv-vlm):

ROOT/index.php

ROOT/.htaccess

RewriteEngine On
Options +FollowSymlinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [NC,QSA]

对于其他网址 (http://example.com/call/rgt-cfjv-vlm):

ROOT/call/index.php

ROOT/call/.htaccess

RewriteEngine On
Options +FollowSymlinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [NC,QSA]

现在它在http://example.com/rgt-cfjv-vlm 上加载ROOT/index.php,在http://example.com/call/rgt-cfjv-vlm 上加载ROOT/call/index.php

我相信会有更好的解决方案,但只是临时使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-28
    • 2015-03-29
    • 1970-01-01
    相关资源
    最近更新 更多