使用重写的.htaccess文件夹名称 [英] rewrite a folder name using .htaccess

查看:285
本文介绍了使用重写的.htaccess文件夹名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道羯羊它可以使用的.htaccess 来重写一个文件夹名称。 我的意思是这样的。

I am wondering wether it's possible to use .htaccess to rewrite a folder name. What I mean is this.

可以说,我有一个像网址:

Lets say I have a url like:

www.site.com/folder1/page.php

现在我想重写网址(例如)

Now I want to rewrite the url to (for example)

www.site.com/apple/page.php

该文件夹1是我网络空间的现有文件夹。

The folder1 is an existing folder on my webspace.

重要:苹果是不是一个文件夹,而只是一个名字

确定这里是一步步的计划:

Ok here is a step by step plan:

  1. 用户类型 www.site.com/folder1/login.php
  2. 在该URL应该重写,而不是重定向的URL www.site.com/apple/login.php
  1. User types www.site.com/folder1/login.php
  2. The url should rewrite and not redirect the url to www.site.com/apple/login.php

这意味着苹果只是一个名字,而不是一个目录。所有code应该刚刚从文件夹1。实际上可以苹果应该仅仅是一个别名文件夹1 。我不能只重命名文件夹1 苹果。为此,我只想重写文件夹1 苹果

This means that apple is just a name and not a directory. All the code should just come from folder1. Acutally apple should just be an alias for folder1. I can't just rename folder1 to Apple. Therefor I would just rewrite folder1 to apple.

推荐答案

mod_rewrite的只能重写/重定向请求的URI。所以,你需要请 /苹果/ ... 来把它改写成相应的 /文件夹1 / ...

mod_rewrite can only rewrite/redirect requested URIs. So you would need to request /apple/… to get it rewritten to a corresponding /folder1/….

试试这个:

RewriteEngine on
RewriteRule ^apple/(.*) folder1/$1

此规则将重写每一个与URI路径 /苹果/ ... 内部以 /文件夹1 / ... 。

This rule will rewrite every request that starts with the URI path /apple/… internally to /folder1/….


修改作为你实际上是在寻找其他方式轮:

Edit    As you are actually looking for the other way round:

RewriteCond %{THE_REQUEST} ^GET\ /folder1/
RewriteRule ^folder1/(.*) /apple/$1 [L,R=301]

本规则的目的是与上述其他规则一起工作。 /文件夹1 / ... 的请求将被外部重定向到 /苹果/ ... 的请求/苹果/ ... 将被内部重写回 /文件夹1 / ...

This rule is designed to work together with the other rule above. Requests of /folder1/… will be redirected externally to /apple/… and requests of /apple/… will then be rewritten internally back to /folder1/….

这篇关于使用重写的.htaccess文件夹名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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