htaccess的子目录的URL根 [英] htaccess subdirectory URLS to root

查看:131
本文介绍了htaccess的子目录的URL根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个子目录中的所有文件重定向到新的根URL。

旧网址是

  www.domain.com/subdirectory/filename-here.html
 

新位置

  www.domain.com/filename.here.html
 

旧网址列在谷歌已经和需要某种重定向这些的。 我敢肯定,htaccess是要走的路在这里,但不确定的解决方案。

解决方案

  RewriteEngine叙述上
重写规则%{REQUEST_URI} ^ /子目录/.*
重写规则子目录/(.*)$ / $ 1 [R = 301,L]
 

这里测试在。如果这是行不通的 - 添加屏蔽到 [^ /] 这样: [^ \ /]

I want to redirect all files in a subdirectory to their new root URL.

Old URLS are

www.domain.com/subdirectory/filename-here.html

New location is

www.domain.com/filename.here.html

Old URLs are listed in Google already and need some sort of redirect for these. I'm sure htaccess is the way to go here, but unsure of the solution.

解决方案

RewriteEngine on
RewriteRule %{REQUEST_URI} ^/subdirectory/.*
RewriteRule subdirectory/(.*)$ /$1 [R=301,L]

Tested on here. If it would not work - add shielding to [^/] in this way: [^\/]

这篇关于htaccess的子目录的URL根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆