与htaccess的重定向问题 [英] Problems with htaccess redirect

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

问题描述

在以下网站: http://htaccess.madewithlove.be/

填写请求的URL与:的http://本地主机/ preFIX /游戏/ U_ID /游戏名

fill the request url with: http://localhost/prefix/games/u_id/game-name

在htaccess的区域将这个:

Put this in the htaccess area:

RewriteEngine On        
RewriteBase /prefix

# stop directory listings
Options -Indexes 

#stops htaccess views
<Files .htaccess>
order allow,deny
deny from all
</Files>        

# redirect game folders     
    RewriteRule ^prefix/games/(.*)$ prefix/protected/files/$1 [L]

# remove .php; use THE_REQUEST to prevent infinite loops
    RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
    RewriteRule (.*)\.php$ $1 [R=301]     

# remove index
    RewriteRule (.*)/index$ $1/ [R=301]

# remove slash if not directory
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} /$
    RewriteRule (.*)/ $1 [R=301]

# add .php to access file, but don't redirect
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteCond %{REQUEST_URI} !/$
    RewriteRule (.*) $1\.php [L]       

ErrorDocument 404 /prefix/error-404.php

结果出来为:的http://本地主机/ preFIX /保护/文件/ U_ID /游戏名

现在,如果我把htaccess的文件,我瓦帕本地主机服务器和GOTO相同的URL,因为我们把在该网站上请求URL。它会返回404找不到网页......,但如果我访问的结果页从测试现场(上面的那个),它加载的index.php页面是存在的。

Now if I put that htaccess file on my wamp localhost server and goto the same url as we put in the request url on that site. it returns 404 page not found... and yet if i visit the result page from the test site (the one above), it loads the index.php page that is there.

重定向不工作对我的本地主机的网站。有任何想法吗? htaccess的文件肯定是在运行。

The redirect is not working for my localhost website. Any ideas? the htaccess file is definitely running.

: ///

我的Apache访问日志的输出:

My Apache access log is outputting:

127.0.0.1 - - [25/Apr/2012:18:44:02 +0100] "GET /prefix/games/u_id/game-name HTTP/1.1" 404 116
127.0.0.1 - - [25/Apr/2012:18:44:02 +0100] "GET /favicon.ico HTTP/1.1" 404 209

修改:: ///

解决了。

推荐答案

的RewriteBase / preFIX 不可能是正确的,如果你的htaccess的根目录中。如果htaccess的是preFIX目录内,您的RewriteRules不应以preFIX。在哪里htaccess的位置?

RewriteBase /prefix can't be correct if your htaccess in inside the root directory. If the htaccess is inside the prefix directory, your rewriterules should not start with prefix. Where is the htaccess located?

这篇关于与htaccess的重定向问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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