2016-08-04 102 views
1

試圖重寫幾個不同的URL而不改變RewriteBase。以下網址查詢:htaccess在不改變RewriteBase的情況下重寫網址而不改變rewritebase

http://example.com/directory1/directory2/job?id=100 
http://example.com/directory3/directory4/profile?id=200 

將成爲:

http://example.com/directory1/directory2/job/100 
http://example.com/directory3/directory4/profile/200 

目前的規則:

RewriteRule ^directory1/directory2/job/([0-9]+)$ ./directory1/directory2/job?id=$1 [L,QSA] 

RewriteRule ^directory3/directory4/profile/([0-9]+)$ ./directory3/directory4/profile?id=$1 [L,QSA] 

完整的htaccess:

<IfModule mod_rewrite.c> 
    <IfModule mod_negotiation.c> 
     Options -MultiViews 
     Options +FollowSymLinks 
    </IfModule> 

    RewriteEngine On 

    # Redirect Trailing Slashes... 
    RewriteRule ^(.*)/$ /$1 [L,R=301] 

    # Handle Front Controller... 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule^index.php [L] 

    RewriteRule ^directory1/directory2/job/([0-9]+)$ ./directory1/directory2/job?id=$1 [L,QSA] 

    RewriteRule ^directory3/directory4/profile/([0-9]+)$ ./directory3/directory4/profile?id=$1 [L,QSA] 

</IfModule> 
+0

那麼有什麼不符合規則的問題? – anubhava

+0

沒有錯誤。用完整的htaccess編輯問題 – Klav

回答

1

有順序的規則:

<IfModule mod_rewrite.c> 
    <IfModule mod_negotiation.c> 
     Options -MultiViews 
     Options +FollowSymLinks 
    </IfModule> 

    RewriteEngine On 

    # Redirect Trailing Slashes... 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)/$ /$1 [L,R=301] 

    RewriteCond %{THE_REQUEST} (/directory1/directory2/job)\?id=([^\s&]+) [NC] 
    RewriteRule^/%1/%2? [R=302,L,NE] 

    RewriteCond %{THE_REQUEST} (/directory3/directory4/profile)\?id=([^\s&]+) [NC] 
    RewriteRule^/%1/%2? [R=302,L,NE] 

    RewriteRule ^(directory1/directory2/job)/([0-9]+)$ $1?id=$2 [L,QSA] 

    RewriteRule ^(directory3/directory4/profile)/([0-9]+)$ $1?id=$2 [L,QSA] 

    # Handle Front Controller... 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule^index.php [L] 

</IfModule> 
+0

感謝您關注此事。我仍然沒有得到任何東西,也沒有錯誤。在其他條件和規則中添加工作得很好。我需要定義一個查詢字符串嗎? – Klav

+1

試試我的更新規則。 – anubhava

+0

$ _GET無法訪問,我認爲這是再次的順序,但是這並沒有幫助 – Klav