使用htaccess的主URL后删除目录目录、htaccess、URL

由网友(凉初)分享简介:通过以​​下网址 http://www.example.com/de/here/我想删除了德的目录(或任何可能在这里目录前,如果有的话,即使是在它前面),因此用户被定向到的 http://www.example.com/here/ 的代替,这​​是指该实际存在的一个目录。With the following url...

通过以​​下网址 http://www.example.com/de/here/我想删除了德的目录(或任何可能在这里目录前,如果有的话,即使是在它前面),因此用户被定向到的 http://www.example.com/here/ 的代替,这​​是指该实际存在的一个目录。

With the following url http://www.example.com/de/here/ I want to remove the "de" directory (or whatever may be in front of the "here" directory, if anything even is in front of it) so a user is directed to http://www.example.com/here/ instead, which is a directory that does actually exist.

网址甚至可以像 http://www.example.com/it/here/ 或2个英文字母的任何其他组合。

The url could even be something like http://www.example.com/it/here/ or any other combination of 2 letters.

网址也只是 http://www.example.com/here/ 在这种情况下,我不希望任何东西全部去掉。

The url could also just be http://www.example.com/here/ in which case I don't want anything removed at all.

我已经寻找这里的解决方案,但不能似乎做什么正常工作,所以任何帮助将是非常美联社preciated。

I have searched for a solution here but cant seem to make anything work correctly so any help would be much appreciated.

推荐答案

您可以使用这种的htaccess的:

You can use this kind of htaccess :

RewriteEngine On
RewriteBase /
RewriteRule ^[A-Za-z]{2}/(.*)$ $1 [L,R=301]

由此引起code重定向的例子:

Example of redirections caused by this code :

http://www.example.com/de/foo/  => http://www.example.com/foo/
http://www.example.com/de/      => http://www.example.com/
http://www.example.com/it/bar/  => http://www.example.com/bar/
http://www.example.com/FR/baz/  => http://www.example.com/baz/

请注意,您将无法访问语言(德,IT,FR ......)了。

Please note you won't be able to access the language (de, it, fr...) anymore.

还有一点,要小心这种URL(重定向将被执行两次)的:

Another point, be careful with this kind of url (the redirection will be executed twice) :

http://www.example.com/de/go/   => http://www.example.com/go/
http://www.example.com/go/      => http://www.example.com/

修改

现在我已经得到了更多的细节,这里是一个htaccess你可以你删除的指定文件夹的语言:

Now I've got more details, here is an htaccess you can you to remove the language for specified folders :

RewriteEngine On
RewriteBase /
RewriteRule ^[A-Za-z]{2}/here/(.*)$          here/$1 [L,R=301]
RewriteRule ^[A-Za-z]{2}/anotherfolder/(.*)$ anotherfolder/$1 [L,R=301]
阅读全文

相关推荐

最新文章