使用htaccess将旧网址重定向到相同域的新网址

时间:2018-06-22 12:58:08

标签: .htaccess url redirect

我想将https://www.example.com/page/jobseekers重定向到https://www.example.com/jobseekers

我用过

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Redirect /page/jobseekers /jobseekers

但是它重定向到https://www.example.com/jobseekers?page/jobseekers

1 个答案:

答案 0 :(得分:1)

将此规则放在RewriteEngine On行的下面:

RewriteEngine On

RewriteRule ^page/(jobseekers)/?$ /$1? [L,NC,R=301]

# other rules go below

在测试之前,请确保在新的浏览器中进行测试或清除浏览器缓存。