如何仅重定向主文件

时间:2015-03-02 11:51:53

标签: apache .htaccess mod-rewrite redirect

我的网站有以下结构

site
    |-- .htaccess
    |-- index.php
    |-- other files and directories

index.php文件用于每个重定向。我如何使用修改.htaccess仅在有人想要访问mydomain.com/desiredLink而不是有人使用mydomain.commydomain.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]

1 个答案:

答案 0 :(得分:1)

您可以使用:

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]