Welcome to WebmasterWorld Guest from 3.227.208.153

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

redirect all queries with mod_rewrite

Why mod_rewrite, why!?

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

Preferred Member

10+ Year Member

joined:Apr 25, 2002
posts:470
votes: 0


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?

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

Preferred Member

10+ Year Member

joined:Apr 25, 2002
posts:470
votes: 0


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.
5:30 am on Jan 21, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


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