Forum Moderators: phranque
I'm trying to rewrite all non-existing files to page.php?p=$1
So I tried to use the following code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9\-\+]+)$ page.php?p=$1 [L]
But now my problem:
why doesn't 'index' rewrite to 'page.php?p=index' ?
'home' rewrites succesfully to 'page.php?p=home'.
What I see as a difference is that index.php exists and home.php doesn't.
So all $1 url's doesn't rewrite if $1.php exists.
If $1.php doesn't exist; It rewrites like it should do.
why doesn't 'index' rewrite to 'page.php?p=index' ?
[httpd.apache.org...]
mod_negotiation registers a type_checker hook, which runs prior mod_rewrite's fixup hook. Your request was internally fast redirected to index.php and your regular expression does not match against index.php. That's why your rule failed to match.
DirectoryIndex page.php?p=homeRewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9\-\+]+)$ page.php?p=$1 [QSA,L]
Going to /?style=4 redirects to /page.php?p=home?style=4
As you see a double ? so style isn't another query, is this possible to fix?
And if that requested URL-path is non-blank (e.g. as a result of the action of the preceding DirectoryIndex directive), then your rule requires that that URL-path *not* resolve to a physically-existing file or directory, and that that URL-path contain only alphanumeric, hyphen, or plus-sign characters (i.e. a request for page.php won't match this pattern, because it contains a period and because page.php exists).
Note that in the first line of this post, I said that your rule should not "rewrite" -- If you are instead seeing a redirect (i.e. the browser address bar changes), then you've likely got another (faulty) rule invoking an external redirect, or one of your scripts is invoking an external redirect. I suppose this might be better news than being told you need to re-install Apache, though... :)
Jim
First for clarifying: It rewrites and doesn't redirects ;)
Second it's a hosts server <snip>
Thirt you're right about the fact it shouldn't rewrite at all.
So I don't think asking the host for re-install they will listen xD
And as it's only a little error (wich normally never happens), I don't gonna put much more time in it. Except as you "mini-experts", knows why it happens and how to fix it.
Anyhow already thanks for the answer
[edited by: jdMorgan at 6:15 pm (utc) on Aug. 23, 2009]