You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Ed Lazor <ed...@d20news.com> on 2003/12/16 07:48:05 UTC

[users@httpd] mod rewrite

Hello,

Is it possible to redirect all site-wide php file requests to a single script?  Is it possible to set this up as the root of the site?

For example, if someone types:

http://localhost/test.php

a script that I specify gets called?

We're moving a lot of pages into a database and will achieve a number of benefits in the process.  Unfortunately, one drawback is that we lose previous naming conventions and end up with odd URLs.

In other words, we end up going from 

http://localhost/TheSuperStory.php

to

http://localhost/view.php?ID=234

One idea is to have all php file requests go to a specific script and have it load documents.  The script could then do a search in the database for the file name and display the proper document.

I'm not sure if I'm making sense here, but the script would process the url

http://localhost/TheSuperStory.php

and search the database for an article titled TheSuperStory and display it from the database.

To play devil's advocate here...  would that be too much over head for mod_rewrite, php, and mysql just for loading a page from the database?

Thanks,

-Ed



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod rewrite

Posted by Andrea Classen <An...@emcdda.eu.int>.
I'd guess something like

RewriteEngine On
RewriteRule ^(.*)\.php$  /view.php?arg=$1 [PT]

should work
Bye, Andrea

Ed Lazor wrote:

>Hello,
>
>Is it possible to redirect all site-wide php file requests to a single script?  Is it possible to set this up as the root of the site?
>
>For example, if someone types:
>
>http://localhost/test.php
>
>a script that I specify gets called?
>
>We're moving a lot of pages into a database and will achieve a number of benefits in the process.  Unfortunately, one drawback is that we lose previous naming conventions and end up with odd URLs.
>
>In other words, we end up going from
>
>http://localhost/TheSuperStory.php
>
>to
>
>http://localhost/view.php?ID=234
>
>One idea is to have all php file requests go to a specific script and have it load documents.  The script could then do a search in the database for the file name and display the proper document.
>
>I'm not sure if I'm making sense here, but the script would process the url
>
>http://localhost/TheSuperStory.php
>
>and search the database for an article titled TheSuperStory and display it from the database.
>
>To play devil's advocate here...  would that be too much over head for mod_rewrite, php, and mysql just for loading a page from the database?
>
>Thanks,
>
>-Ed
>
>
>
>---------------------------------------------------------------------
>The official User-To-User support forum of the Apache HTTP Server Project.
>See <URL:http://httpd.apache.org/userslist.html> for more info.
>To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
>For additional commands, e-mail: users-help@httpd.apache.org
>
>  
>



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod rewrite

Posted by Jonas Eckerman <jo...@frukt.org>.
On Mon, 15 Dec 2003 22:48:05 -0800, Ed Lazor wrote:

>  Is it possible to redirect all site-wide php file requests to a
>  single script?  Is it possible to set this up as the root of the
>  site?

What about something like (note: untested):
RewriteCond %{REQUEST_URI} !^/view.php$
RewriteRule ^(.*)\.php$ /view.php?file=$1.php [NC,PT,QSA]

If you'r using a case insensitive file system, put a [NC] at the end of the rewrite condition as well.

>  To play devil's advocate here...  would that be too much over head
>  for mod_rewrite, php, and mysql just for loading a page from the
>  database?

Probably not. It's not uncommon to use rewrite rules to "hide" the fact that pages are loaded through a script or application.

Regards
/Jonas

Regards
/Jonas

-- 
Jonas Eckerman, jonas_lists@frukt.org
http://www.fsdb.org/


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org