Forum Moderators: phranque

Message Too Old, No Replies

redirect all queries with mod_rewrite

Why mod_rewrite, why!?

         

Filipe

4:59 am on Jan 21, 2004 (gmt 0)

10+ Year Member



Okay, I'm building an application in PHP based on the MVC model, and so I need all queries rerouted to the /index.php file (which will parse the url and act accordingly).

So I want a request like:

[domain.com...]

to be changed to:

[domain.com...]

so I figured it would be enough to:

RewriteBase /
RewriteRule /(.*) /index.php?q=$1

but I was wrong. Am I crazy?

Filipe

5:27 am on Jan 21, 2004 (gmt 0)

10+ Year Member



Erp, nevermind. I turns out the reason it's not working is because I put it in .htaccess instead of httpd.conf... but it's not recognizing it when I put in .htaccess for some reason.

jdMorgan

5:30 am on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Filipe,

Where are you placing this code, in httpd.conf or in .htaccess? The syntax is subtly different, in that leading slashes are stripped from the URI seen by RewriteRule in the .htaccess context.

Therfore, you may need to delete the leading slash for use in .htaccess:

 RewriteRule (.*) /index.php?q=$1

Also, you may need

Options +FollowSymLinks
RewriteEngine on

ahead of your code.

Other than that, you've got most of it.

One warning: make sure that your script will NOT return a 200-OK and content for all possible requested URIs... If you do not return 404 under any circumstances, then search engines will see your site as a spider trap - an infinite URI-space where a spider might follow links forever. Therefore, they set an artificially-low depth of spidering on such sites, and you won't easily get all your pages indexed. Some basic syntax-checking and URI-validity checking of URIs before returning content will usually suffice.

Jim