PDA

View Full Version : .htaccess and mod_rewrite mystery


End User
10-29-05, 12:57 PM
Heck if I can figure this one out. Who knows a little bit about mod_rewrite?

Here's the URL I'm trying to get mod_rewrite to change:

http://mydomain.net/tree.php?grp_id=14&begin=0

Every tutorial shows more or less the same thing, that is, to use an .htaccess statement like this:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)-(.*).html tree.php?grp_id=$1&begin=$2

I've tried a ton of variations on this and can't get it to do a thing. It doesn't rewrite the URLs at all, nor do anything else.

Does the .htaccess file have to go any place(s) besides the root? The .htaccess file is being "seen" by the server as it contains a couple of other directives to set the error pages and those appear to be working. The weird thing is that mod_rewrite appears to be working fine on a couple of other domains on the same box. (??)

Okay, so my head e'splode. Anyone have any ideas on what it is I'm doing wrong?

chuck59
10-29-05, 02:36 PM
try the following...

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^tree([0-9]+)-([0-9]+).html$ tree.php?grp_id=$1&begin=$2 [L]


To view this page working, access it like
http://mydomain.net/tree14-0.html

As tree.php is placed under root of your site, .htaccess should also be present at the root location. You can write seperate .htaccess file for each directory.

nugensoftware
10-30-05, 03:16 AM
i would also verify that your server is configured for mod_rewrite. since it can cause serverload some hosting companys do not have it enabled.

End User
10-31-05, 03:19 AM
I used your example, and here's what I've got in .htaccess in the root directory:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^tree([0-9]+)-([0-9]+).html$ tree.php?grp_id=$1&begin=$2 [L]
php_flag register_globals 0


The directives have no effect at all, just like the variations I've tried. I'd think it was at the server level, but phpinfo() reports this:

Loaded Modules
mod_php4, mod_frontpage, mod_setenvif, mod_auth_db,
mod_auth_dbm, mod_auth, mod_access, mod_rewrite,
. . .etc etc

So I dunno what to think....I'm stumped for the moment.

nugensoftware
10-31-05, 06:24 AM
here is an example of mod_rewrite i supplied another user with. its been a long time since i've had to mess with it. this file stops linking from external sites and my own internal network, allowing only traffic from mw-dnb.com to access mp3, wav, and rex files. if a user outside the network would request the file it would rewrite the url to mw-dnb.com

hope it helps...

mod_rewrite is for rewriting users requests at the server level (apache) not the information interpretation level (php).

an example of mod_rewrite would be to use it stop hot linking to files on your site. generally mod_rewrite is controlled in the .htaccess

This is an example of mod_rewrite allowing only users from mw-dnb.com to access files with the .mp3 file extension. these domains are no longer up but the quickest .htaccess i had with an example of mod_rewrite.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://dnbsearch.planet32.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://dnbsearch.planet32.net$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mw-dnb.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mw-dnb.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://neo.planet32.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://neo.planet32.net$ [NC]
RewriteCond %{HTTP_REFERER} !^http://planet32.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://planet32.net$ [NC]
RewriteCond %{HTTP_REFERER} !^http://ujn.planet32.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://ujn.planet32.net$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.dnbsearch.planet32.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.dnbsearch.planet32.net$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mw-dnb.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mw-dnb.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.neo.planet32.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.neo.planet32.net$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.planet32.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.planet32.net$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.ujn.planet32.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.ujn.planet32.net$ [NC]
RewriteRule .*\.(mp3|wav|rex)$ http://www.mw-dnb.com [R,NC]