重写URL以htaccess的当一个目录存在 [英] Rewriting url with htaccess when a directory exists

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

问题描述

我想要一个动态页面重定向到一个目录,例如:

  url.com/index.php?page=download
至
url.com/download
 

规则很简单:

 重写规则^下载$ /index.php?page=download
 

FULL的.htaccess

  RewriteEngine叙述上
的RewriteBase /

的RewriteCond%{HTTP_HOST}!^ WWW \ .URL \ .COM $
重写规则^(。*)http://url.com/$1 [R = 301,L]

重定向301 /index.php?page=download http://url.com/download
的RewriteCond%{ENV:REDIRECT_STATUS} 200
重写规则。*  -  [L]
重写规则^下载$ /index.php?page=download
 

现在的问题是,我已经有一个名为下载和它的返回我一个403 Forbidden错误目录。 我注意到,重命名目录以外的任何规则的使用将工作名称(下载)不同。

所以,我的问题是:我怎么能有我的网址重写,我需要的方式,并保持目录

- 编辑 -

我的服务器,默认情况下,保护与403 Forbbiden错误的每个目录。我相信,这就是为什么它不工作的原因,但我不知道。 它是一个矛盾真的是吗? 这是怎么回事?

解决方案

  /下载/?页=下载
 

为什么发生这种情况的原因是什么地方mod_dir重定向对于那些缺少尾随斜线后面的斜线目录的所有请求。这是interferring你重写规则。因为你的服务器会自动设置为拒绝目录的上市,它可能是安全的,继续前进,把目录斜线关闭:

  DirectorySlash关闭
 

通过答案:<一href="http://stackoverflow.com/users/851273/jon-lin">http://stackoverflow.com/users/851273/jon-lin

I'm trying to redirect a dynamic page to a dir, example:

url.com/index.php?page=download
to
url.com/download

The rule is very simple:

RewriteRule ^download$ /index.php?page=download

FULL .HTACCESS

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.url\.com$
RewriteRule ^(.*) http://url.com/$1 [R=301,L]

Redirect 301 /index.php?page=download http://url.com/download
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
RewriteRule ^download$ /index.php?page=download

The problem is that I already have a directory named "download" and it's returning me a "403 Forbidden Error". I have noticed that renaming the directory to anything different than the name (download) the rule is using will work.

So, my question is: how can I have my url rewritten the way I need and keep the directory?

-- EDIT --

My server, by default, protects every directory with a "403 Forbbiden Error". I believe this is the reason why it's not working, but I'm not sure. Is it a conflict indeed? What is happening?

解决方案

/download/?page=download

The reason why this is happening is because somewhere mod_dir redirects all requests for directories that are missing the trailing slash to include the trailing slash. This is interferring with your rewrite rule. Since your server is automatically setup to deny listing of directories, it's probably safe to go ahead and turn directory slashes off:

DirectorySlash Off

Answer by: http://stackoverflow.com/users/851273/jon-lin

这篇关于重写URL以htaccess的当一个目录存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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