3

I want http://my_domain.com/forum/index.php/blah_blah_blah to not being redirected to anywhere.

But I want http://my_domain.com/something_else_that_is_not_forum/blah_blah_blah to be redirected to http://my_domain.com/index.php/something_else_that_is_not_forum/blah_blah_blah

So basically, only everything without http://my_domain.com/forum/ prefix should be redirected.

I have this .htaccess:

<IfModule mod_rewrite.c>
    # Options +FollowSymLinks -Indexes
    RewriteEngine On
    RewriteBase /

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    #RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    RewriteRule ^(?!forum.*)(.*)$ index.php/$2 [L,QSA]
</IfModule>

I think the regex should do exactly what I want, but in this case, seems that I'm wrong. http://www.getnocms.com/forum/index.php?action=admin;area=manageboards;sa=newcat;df105e678e9b=e1a979a0631bd203b6794debc16ceced

Does anybody know how to do that correctly?

EDIT: I use this

<IfModule mod_rewrite.c>
    # Options +FollowSymLinks -Indexes
    RewriteEngine On
    RewriteBase /

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteCond %{REQUEST_URI} !^\/forum 
    RewriteRule (?!^forum(?:/.*|)$)^(.*)$ /index.php/$1 [L,NC,QSA]
</IfModule>

That roughly say: If request is not pointed to file or directory or symbolic link, and it is not /forum then If it is not started with forum, then point to /index.php/url.

It seems to be logical (well, we don't need RewriteCond %{REQUEST_URI} !^\/forum actually), but it still failed when accessing this url: http://www.getnocms.com/forum/index.php?action=admin;area=manageboards;sa=newcat;a5272d5=2fcf142818fc9df2aabb1364942a1d14

Maybe rewrite rule doesn't work with semicolon? I'm not sure.

goFrendiAsgard
  • 4,016
  • 8
  • 38
  • 64

3 Answers3

1
RewriteRule !^forum/ index.php/something_else_that_is_not_forum/blah_blah_blah

Anything that doesn't begin with...

Kohjah Breese
  • 4,008
  • 6
  • 32
  • 48
1

Your rules are almost correct but some minor changes are needed. Replace your code with this:

<IfModule mod_rewrite.c>
    # Options +FollowSymLinks -Indexes
    RewriteEngine On
    RewriteBase /

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule (?!^forum(?:/.*|)$)^(.*)$ /index.php/$1 [L,NC]
</IfModule>
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Very reasonable. Your rule seems to be logical. However, accessing this url: http://www.getnocms.com/forum/index.php?action=admin;area=manageboards;sa=newcat;a5272d5=2fcf142818fc9df2aabb1364942a1d14 seems to also be redirected into /index.php – goFrendiAsgard May 18 '13 at 23:18
  • I had actually posted this after testing it locally and I retested these rule with your URL and it still worked fine and didn't goto `/index.php` Are you sure this is the only code in your .htaccess and there is no other .htaccess in some other subdir? – anubhava May 19 '13 at 04:51
  • I'm sure, I suspect there is a trouble with ";" character. This is work http://www.getnocms.com/forum/index.php?action=admin&area=manageboards&sa=newcat&feb4219=bea74b1ac6aace220b204cb50a5d5027 while this is not: http://www.getnocms.com/forum/index.php?action=admin;area=manageboards;sa=newcat;feb4219=bea74b1ac6aace220b204cb50a5d5027 However I'll accept your answer as the most complete one, and maybe start a new question as the problem has been narrowed – goFrendiAsgard May 19 '13 at 05:08
  • I've make a new question: http://stackoverflow.com/questions/16631786/is-rewritecond-doesnt-work-with-semicolon in case of you are interested to answer. Thanks :) – goFrendiAsgard May 19 '13 at 05:39
  • Thanks for your accepting the answer, I will make an attempt to solve your new question. – anubhava May 19 '13 at 05:43
0

You could also try:

RewriteCond %{REQUEST_URI} !^/forum 
RewriteRule ^(.)$ http://domain.com/$1
Kohjah Breese
  • 4,008
  • 6
  • 32
  • 48