如何将基本网址重定向到 .htaccess 中的特定网址?



我想将我的主页重定向到/home。我该怎么做?

RewriteRule ^[a-z]{0}$ /home //doesnt work

我的整个.htaccess:

Options FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]+)$ ?site=$1

我需要实现的目标示例:

blue-world.pl > blue-world.pl/home > blue-world.pl?site=home
blue-world.pl/contact > blue-world.pl?site=contact

根据您显示的示例,您能否尝试以下操作。 请确保在测试您的 URL 之前清除浏览器缓存。

Options FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(home|.*blue-world.pl)/?$ ?site=$1 [L]

说明:只需在重写 URL(主页)时检查条件部分,如果 uri 从/或没有 开始,则将其重写为/home。我也在这里使用L标志来停止此规则(重写规则)。如果这是 .htaccess 文件中唯一的规则,那么您也可以将上面的L标志更改为END标志。还有一点,这考虑到您的主目录/文件夹在 root 中,如果不是这种情况,则从上面的/home更改为home.

您可以在您的网站根目录 .htaccess 中尝试以下规则:

DirectoryIndex index.php index.html
RewriteEngine On
# use ENV:REDIRECT_STATUS="" condition to avoid a redirect loop
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^$ /blue-world.pl/home [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .+ ?site=$0 [L,QSA]

最新更新