重定向内容而不更改htaccess文件中的url

时间:2019-06-11 09:06:48

标签: regex wordpress apache .htaccess url-redirection

在Wordpress上,我们希望我们的网址指向:

  • 来自 mysite / education / somethingse
  • 访问 mysite / somethingse

但是,而无需更改用户的网址。

我尝试过这个:

RewriteRule ^education/(.*) /$1 [R=301]

还有

RewriteCond %{REQUEST_URL} /education

RewriteRule ^(.*) $1 [P]

.htaccess文件

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# RewriteRule ^education/(.*) /$1 [R=301]
# RewriteCond %{REQUEST_URL} /education
# RewriteRule ^(.*) $1 [P]
# RewriteRule /education ^$ [L]
# RewriteRule /education ^$ [R=301,NC,L]
# RewriteCond %{HTTP_HOST} /education
# RewriteRule ^(.*) $1 [P]
RewriteRule ^/education/(.*) /$1
</IfModule>

它没有用:它重定向到新的url,但它不断更改url!

请问有什么想法吗?

1 个答案:

答案 0 :(得分:1)

修改您对此规则的重写

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^education\/(.*) /$1 [L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>