Problems with htaccess redirect

可紊 提交于 2019-12-25 01:44:32

问题


On the following site: http://htaccess.madewithlove.be/

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

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

The result comes out as: http://localhost/prefix/protected/files/u_id/game-name

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.

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

EDIT::///

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

EDIT::///

SOLVEd.


回答1:


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?



来源:https://stackoverflow.com/questions/10307943/problems-with-htaccess-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!