.htaccess tutorial

htaccess Elite


mod_rewrite Conditions with PHP GET and title.

Ask your mod_rewrite and Redirection questions here, and get answers!

mod_rewrite Conditions with PHP GET and title.

New postby NeXEA » 01 Mar 2009 17:56

The title sounds very confusing, but this is the stuff that I can't seem to get.

I have the URL
files.php?id=5

and the 5 is the ID of the row in my database(MySQL).

I have seen this be done other places where it is rewritten to
files/5/TITLE_Of_ROW

Is this with mod_rewrite or is this more of a PHP thing.
EDIT:

Hopefully this helps a little bit.

My .htaccess is
Code: Select all
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!

RewriteRule ^(.*)$ index.php [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]

Options +FollowSymLinks
RewriteEngine on
RewriteRule details/id/(.*)/ details.php?id=$1
RewriteRule details/id/(.*) details.php?id=$1


The first few lines with comments I borrowed from a script for security purposes.
The first four lines starting with the RewriteRule ^ are to allow requests for index instead of index.php.

The last five lines I got from
http://www.webconfs.com/url-rewriting-tool.php
and when I try it, I get an error.
Is there something wrong with how it is layed out.

Thanks for any help
-NeXEA
NeXEA
 
Posts: 1
Joined: 01 Mar 2009 17:49

Re: mod_rewrite Conditions with PHP GET and title.

New postby mod_rewrite » 07 Mar 2009 08:18

Code: Select all
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule ^(.*)$ index.php [F,L]


Ok that makes sense, the problem is the last rewritecond doesn't have a rewriterule to apply to..
mod_rewrite
 
Posts: 102
Joined: 30 Oct 2006 19:55


Return to Redirect or Rewrite Questions