Topic: .htaccess issues

Hey all,

I have this in my .htaccess:

RewriteEngine On
RewriteRule ^([^/]+)/([^/]*)\?([^/]*)$ base_forum/$2?$3&forum_name=$1 [L,NC]
RewriteRule ^([^/]+)/([^/]*)$ base_forum/$2?forum_name=$1 [L,NC]
RewriteRule ^([^/]+)$ base_forum/?forum_name=$1 [L,NC]

As you might guess, it should rewrite links of the form

http://www.server.com/forumname/index.php

to

http://www.server.com/base_forum/index.php?forum_name=forumname

Unfortunately, it doesn't sad Instead of giving me the forum name, it gives me 'base_forum' =/

Any idea why might be causing it?

Re: .htaccess issues

because "forumname/index.php" is not matched by the regex "^([^/]+)/([^/]*)\?([^/]*)$" but is matched by "^([^/]+)/([^/]*)$" and thus rewrites your url as base_forum/$2?forum_name=$1 where:
$1 = forumname
$2 = index.php

in your index.php dump the get array to see if forum_name is there.

Re: .htaccess issues

I've been outputting some stuff smile

$_GET['forum_name'] = base_forum 
$_SERVER['REQUEST_URI'] = /Digitware%20hosting/support/index.php

And the output of apache_lookup_uri($_SERVER['REQUEST_URI']):
stdClass Object
(
    [status] => 200
    [the_request] => GET /Digitware%20hosting/support/index.php HTTP/1.1
    [method] => GET
    [mtime] => 0
    [clength] => 0
    [chunked] => 0
    [no_cache] => 0
    [no_local_copy] => 1
    [unparsed_uri] => /Digitware%20hosting/support/index.php
    [uri] => /Digitware hosting/support/index.php
    [filename] => D:/webserver/www/Digitware hosting/support
    [path_info] => /index.php
    [allowed] => 0
    [sent_bodyct] => 0
    [bytes_sent] => 0
    [request_time] => 1166804461
)

That's how I figured out it was matching the wrong thing (that isn't even in the URL!).

Re: .htaccess issues

is that in your root .htaccess file?  if so are those the only rewrite rules in there?

Re: .htaccess issues

Those are the only rewrite rules there yes (it's all that's in the .htaccess file too), and it's in the 'root' directory yes.

Re: .htaccess issues

After seriously logging stuff, I noticed that the [L] modifier doesn't stop rule parsing >=/

Re: .htaccess issues

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^([^/]+)(/([^/]*))?$ /base_forum/$3?forum_name=$1 [QSA,L]

The L flag stops the rewrite engine for that request. But once a rule has matched and needs to be internally rewritten, it is a new sub request, and goes through mod_rewrite processing again. The condition stops mod_rewrite from rewriting any sub requests.

Re: .htaccess issues

Cool smile It's much cleaner than the solution I had found by now (adding a RewriteRule for the base_forum tongue).

But now I have another problem... I can't access any normal files or folders in that specific directory anymore tongue The directories don't matter, but the files do...

Thanks smile

Re: .htaccess issues

You could try something like this:

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)(/([^/]*))?$ /base_forum/$3?forum_name=$1 [QSA,L]

Re: .htaccess issues

It's odd how you guys always post right after I solved it... tongue
I just changed
[^/]
to
[^/|.]