Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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
Apache 如何仅重定向主文件_Apache_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Apache 如何仅重定向主文件

Apache 如何仅重定向主文件,apache,.htaccess,mod-rewrite,redirect,Apache,.htaccess,Mod Rewrite,Redirect,我有这个网站,有以下结构 site |-- .htaccess |-- index.php |-- other files and directories index.php文件用于每个重定向。我如何使用modify the.htaccess仅在有人想要访问mydomain.com时重定向到mydomain.com/desiredLink,而不是在有人使用mydomain.com/otherlink或mydomain.com/index.php?stuff时重定向到 当

我有这个网站,有以下结构

site
    |-- .htaccess
    |-- index.php
    |-- other files and directories
index.php
文件用于每个重定向。我如何使用modify the
.htaccess
仅在有人想要访问
mydomain.com
时重定向到
mydomain.com/desiredLink
,而不是在有人使用
mydomain.com/otherlink
mydomain.com/index.php?stuff
时重定向到

当前.htaccess内容如下:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|resources|assets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
您可以使用:

RewriteEngine on
RewriteBase /

# redirect root URL
RewriteRule ^/?$ /desiredLink [L,R]

# other than root URL
RewriteCond $1 !^(index\.php|resources|assets|robots\.txt) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [L]