Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess-在没有特定单词或其他文件时加载index.php_Php_Apache_.htaccess_Mod Rewrite_Url Rewriting - Fatal编程技术网

.htaccess-在没有特定单词或其他文件时加载index.php

.htaccess-在没有特定单词或其他文件时加载index.php,php,apache,.htaccess,mod-rewrite,url-rewriting,Php,Apache,.htaccess,Mod Rewrite,Url Rewriting,默认情况下,我想加载index.php,但如果url中有call或call.php,则应该加载call.php文件: 默认URL(下面的URL应加载ROOT/index.php): http://example.com/rgt-cfjv-vlm http://example.com/index.php/rgt-cfjv-vlm http://example.com/call/rgt-cfjv-vlm http://example.com/call.php/rgt-cfjv-vlm 其他URL

默认情况下,我想加载
index.php
,但如果url中有
call
call.php
,则应该加载call.php文件:

默认URL(下面的URL应加载ROOT/index.php):

http://example.com/rgt-cfjv-vlm
http://example.com/index.php/rgt-cfjv-vlm
http://example.com/call/rgt-cfjv-vlm
http://example.com/call.php/rgt-cfjv-vlm
其他URL(URL下面应加载ROOT/call.php):

http://example.com/rgt-cfjv-vlm
http://example.com/index.php/rgt-cfjv-vlm
http://example.com/call/rgt-cfjv-vlm
http://example.com/call.php/rgt-cfjv-vlm
注意“rgt cfjv vlm”是一个随机字符串,它总是出现在URL中

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

给你:

RewriteEngine on

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

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


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

默认URL():

http://example.com/rgt-cfjv-vlm
http://example.com/index.php/rgt-cfjv-vlm
http://example.com/call/rgt-cfjv-vlm
http://example.com/call.php/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]
RewriteEngine On
Options +FollowSymlinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [NC,QSA]
对于其他URL():

http://example.com/rgt-cfjv-vlm
http://example.com/index.php/rgt-cfjv-vlm
http://example.com/call/rgt-cfjv-vlm
http://example.com/call.php/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]
RewriteEngine On
Options +FollowSymlinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [NC,QSA]
现在在
http://example.com/rgt-cfjv-vlm
上的ROOT/call/index.phphttp://example.com/call/rgt-cfjv-vlm


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

apache别名(别名“/call”,后面是目录,您可以将DirectoryIndex放在其中作为call.php),这也会work@TranquillityI无法使用此htaccess访问apache设置浏览器,其加载call.php始终包含两个URL。i、 e.
http://example.com/rgt-cfjv-vlm 和http://example.com/index.php/rgt-cfjv-vlm
不应该这样做。您是否在第二个条件中添加了“!”。第一个条件是,如果URL包含call,则加载call.php;第二个条件是,如果URL不包含call,则调用index.php。我已经测试过了。您的htaccess中还有其他重定向吗?我正在使用您提供的.htaccess。没有,my.htaccess中没有额外的代码,但仍然通过anymean[link]加载call.php。把我的htaccess复制到这里,然后写下你的URL来测试:或者其他任何东西。请检查,其本地主机可通过ngrok共享url