.htaccess HTACCESS从www.url.com重定向到www.url.com/home
我正在使用以下htaccess文件实现一些重定向等:.htaccess HTACCESS从www.url.com重定向到www.url.com/home,.htaccess,.htaccess,我正在使用以下htaccess文件实现一些重定向等: RewriteEngine On Options +FollowSymLinks RewriteEngine on RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] RewriteCond %{H
RewriteEngine On
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTPS} !=on
RewriteRule .* https://www.myurl.com/$1 [R,L]
RewriteRule ^$ /home [R=301,L]
最近我添加了最新的一行,所以当用户访问时,他会被重定向到主页。这很好,但我有一个坏的感觉,这应该写得更好。我不喜欢^$部分,但它很有效。我怎样才能重写它?当然可以重写
HTTPS
部分,并且在创建多个重定向时,应该首先重写该部分
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
#redirect all traffic looking for a domain not starting with www &
#all non-https traffic to the https://www domain
RewriteCond %{HTTPS} off
#This condition is better for analytics tracking and SEO (single subdns)
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteRule ^$ home [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
由于MVC可能使用index.php处理所有请求,因此重定向到/home
很可能无法工作,除非您访问网站时没有请求任何文件(仅根目录)。如果有人明确要求https://www.myurl.com/index.php
您的规则是RewriteRule^index\.php$-[L]
告诉站点不要更改任何内容。既然你说这是预期的工作,我没有改变顺序
如果未按预期工作,则切换/home
规则的顺序
RewriteRule ^$ home [R=301,L]
RewriteRule ^index\.php$ - [L]
您是否已将所有文件从根目录
/
移动到/home/
目录?否。这是一个MVC php网页。因此/index.php
是旧主页,并重定向到/home/
,但您希望所有其他文件夹仍位于预期位置(例如/contact/
)?是的,正确。www.url.com/index.php/sth转到www.url.com/sth,www.url.com转到www.url.com/home伟大的答案我一定会用它。