Nik
Nik

Reputation: 7273

mod_rewrite Rules Giving 404

I'm sure this has been answered, I've been reading for a few hours now and am getting nowhere. I need this to work tonight and my brain is hurting, so I'm asking the the wonderful internet for help.

I'm trying to run all my pages through index_new.php (it all made sense when I decided to do that, I swear). I have two types of pages, static and dynamic. The dynamic pages are all the same kind of page, but with different data based on the database (MySQL). I'm trying to make these rewrites

(I'd love if about could be generic, but I don't want to push my luck) My .htaccess file is:

# enable rewrite
Options +FollowSymLinks
RewriteEngine On
RewriteBase /

# rewrite all physical existing file or folder
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d

# allow things that are certainly necessary
RewriteCond %{REQUEST_URI} "/statics/" [OR]
RewriteCond ${REQUEST_URI} "/ajax/"

# rewrite rules
RewriteRule ^about index_new.php?page=about
RewriteRule ^/installations index_new.php?page=list
RewriteRule ^/installations/(.*) index_new.php?page=site&id=$1

When I try to go to /about or any other page, I get HTTP 404. As a note, my root is http://localhost/~user/public_html/new and the .htaccess file is there.

Upvotes: 0

Views: 823

Answers (1)

Felipe Alameda A
Felipe Alameda A

Reputation: 11799

Provided:

  1. The conditions in the question have to be met for each rule. (They are repeated as they are valid only for the next rewrite rule).

  2. The .htaccess file is located at root.

You may try this instead of the rule-set in your question:

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}  /about/?$      [NC]
RewriteRule .*  /index_new.php?page=about [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}  /installations/?$ [NC]
RewriteRule .*  /index_new.php?page=list     [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}  /installations/([^/]+)/? [NC]
RewriteRule .*       /index_new.php?page=site&id=%1 [NC,L]

Maps silently:

http://example.com/about to

http://example.com/index_new.php?page=about


http://example.com/installations to

http://example.com/index_new.php?page=about


http://example.com/installations/Anything to

http://example.com/index_new.php?page=site&Anything


For permanent and visible redirection, replace [NC,L] with [R=301,NC,L].

NOTE:

These conditions in the question were not used as their purpose is not clear:

   RewriteCond %{REQUEST_URI} "/statics/" [OR]
   RewriteCond ${REQUEST_URI} "/ajax/"

To include them for one or several rules, try this:

# For NOT condition, include the next line before the corresponding rewrite rule:
RewriteCond %{REQUEST_URI} !(statics|ajax) [NC]
       
# For positive condition, include the next line before the corresponding rewrite rule:
RewriteCond %{REQUEST_URI}  (statics|ajax) [NC] 

Upvotes: 2

Related Questions