2013-05-17 57 views
3

我想http://my_domain.com/forum/index.php/blah_blah_blah不被重定向到任何地方。重寫規則爲一切,但某些模式

但我想http://my_domain.com/something_else_that_is_not_forum/blah_blah_blah被重定向到http://my_domain.com/index.php/something_else_that_is_not_forum/blah_blah_blah

因此,基本上,只是沒http://my_domain.com/forum/前綴一切都應該被重定向。

我有這個.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> 

我認爲,正則表達式應該做的正是我想要的,但在這種情況下,看來我錯了。 http://www.getnocms.com/forum/index.php?action=admin;area=manageboards;sa=newcat;df105e678e9b=e1a979a0631bd203b6794debc16ceced

有沒有人知道如何正確地做到這一點?

編輯: 我用這個

<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> 

,大約說: 如果請求沒有提出任何文件或目錄或符號鏈接,如果它不與啓動它不是/forum然後 論壇,然後指向/index.php/url。 http://www.getnocms.com/forum/index.php?action=admin;area=manageboards;sa=newcat;a5272d5=2fcf142818fc9df2aabb1364942a1d14

也許重寫規則不與分號工作:

這似乎是合乎邏輯訪問此網址時(當然,我們並不需要RewriteCond %{REQUEST_URI} !^\/forum實際上),但它還是沒有?我不確定。

回答

1

你的規則幾乎是完全正確的,但需要進行一些小的改動。這種替換代碼:

<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> 
+0

非常合理。你的規則似乎是合乎邏輯的。但是,訪問此網址:http://www.getnocms.com/forum/index.php?action=admin;area=manageboards;sa=newcat;a5272d5=2fcf142818fc9df2aabb1364942a1d14似乎也被重定向到/index.php – goFrendiAsgard

+0

你能請看看我編輯的問題? – goFrendiAsgard

+0

我在本地測試後發佈了這個,我重新測試了這些規則,並且它仍然正常工作,並且沒有轉到'/ index.php'你確定這是你的.htaccess中唯一的代碼,並且沒有其他.htaccess中的其他subdir? – anubhava

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

凡是不開始...

+0

我仍然需要的URL,所以我想我應該這樣做:1 重寫規則^論壇/(.*)$的index.php/$ [L,QSA] 但仍然不起作用 – goFrendiAsgard

+0

我有這樣的東西適合我。 嘗試幾個變種:​​ RewriteRule!^/forum /;重寫規則!^ /論壇 –

0

您也可以嘗試:

RewriteCond %{REQUEST_URI} !^/forum 
RewriteRule ^(.)$ http://domain.com/$1 
+0

謝謝,它仍然不起作用,但 – goFrendiAsgard