2

If I decide to place this in my file:

IndexIgnore */*
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page_request=$1 [QSA,L]

The site runs fine. I then decided to mv index.php subdir/index.php, so I change the last line to the following:

RewriteRule ^(.*)$ /subdir/index.php?page_request=$1 [QSA,L]

And all I see is an Apache directory listing. What am I doing wrong? This probably a very simple solution, but my resources haven't turned up anything.

What bothers me is that this should work. It is intuitive and natural to think that all that is needed is to change the file location of index.php.

Edit

I have tried RewriteBase, and RewriteCond %{REQUEST_URI} !/subdir/index.php. Neither has worked.

4

5 回答 5

2

Have you tried enabling rewrite logging? Try adding this to your vhost:

RewriteLogLevel 3
RewriteLog "/usr/local/var/apache/logs/rewrite.log"

The rule you posted seems to work just fine for me...

Edit:

Ok I was able to replicate the issue on my Mac and figured out that this is what you need:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ subdir/index.php?page_request=$1 [QSA,L]

RewriteCond %{REQUEST_URI} /
RewriteRule ^(.*)$ subdir/index.php?page_request=$1 [QSA,L]

The problem is, when you just go to http://localhost/ %{REQUEST_FILENAME} doesn't have a value. There might be a way to combine these rules into one, but I haven't figured it out yet.

Edit 2:

I just tried this and it also worked:

DirectoryIndex subdir/index.php

RewriteEngine On   
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ subdir/index.php?page_request=$1 [QSA,L]

However, it doesn't have anything for the value of the page_request $_GET variable, so you'd have to handle that case in your code.

This works because you're telling Apache to look in the subdirectory for the index page instead of the current directory.

于 2012-06-13T00:09:14.623 回答
0

Try removing the slash..

RewriteRule ^(.*)$ subdir/index.php?page_request=$1 [QSA,L]
于 2012-06-12T14:40:37.513 回答
0

RewriteRule ^(.*)$ ./subdir/index.php?page_request=$1 [QSA,L]

于 2012-06-12T15:03:15.533 回答
0
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/subdir/index.php 
RewriteRule (.*) /subdir/index.php?page_request=$1 [QSA,L]
于 2012-06-12T18:35:11.060 回答
-1

Use this:

 RewriteRule ^(.*)$ subdir/index.php?page_request=$1 [QSA,L]
于 2012-06-12T14:40:33.193 回答