.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