如何在.htacess

时间:2018-07-19 15:09:05

标签: .htaccess

因此,出于SEO的目的,我必须更改.htaccess中的网址,我已经在网站的主目录中有了一个.htaccess文件...

我是否需要在主目录或子目录下的.htaccess上进行更改,该目录是我需要具有新URL的网页?

这是我已经在主目录中的代码

RewriteEngine On
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Redirect /public_html/cursos/YoutuberKids/index.php /public_html/cursos- 
kids/Youtuber/index.php

这是必须更改的页面的实际URL:

https://www.viahavok.com.br/cursos/GameDesignPRO/

我需要成为此URL:

https://www.viahavok.com.br/cursos/game-design-pro

2 个答案:

答案 0 :(得分:0)

为什么不将文件夹名称更改为'game-design-pro'?在这种情况下,更改SEO中的.htaccess中的URL不会更好或更有效。 (除非我误解了您的问题?)

答案 1 :(得分:0)

将此添加到主目录中.htaccess文件的底部:

RewriteRule ^cursos/GameDesignPRO/(.*)$ /cursos/game-design-pro/$1 [R=301,NC,L]

这将重定向目录中的所有资源。

  • R=301表示这是对 资源。
  • [L] flag使mod_rewrite停止处理规则集。 在大多数情况下,这意味着如果规则匹配,就不会再有其他 规则将被处理。
  • [NC] flag使RewriteRule在一个 不区分大小写的方式。