问题
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