2012-01-20 35 views
9

Mam problem z ponownym przepisaniem adresu URL..htaccess Przepisywanie adresu URL

Wszystkie poniższe elementy działają poprawnie, ale muszę dodać regułę, która usuwa kwerendy z adresów URL.

site.com/page?a=b staną site.com/page

Czy ktoś może pomóc? Zrobiłem trochę czytania. Htaccess, ale uważam, że jest to bardzo skomplikowane. Ponadto trzeba będzie wiedzieć, gdzie w pliku powinny pojawiać się moje nowe dyrektywy.

Dzięki.

 

    # EE 404 page for missing pages 
    ErrorDocument 404 /index.php/404/index 

    # Simple 404 for missing files 
    
     ErrorDocument 404 "File Not Found" 
    

    # Rewriting will likely already be on, uncomment if it isnt 
    
    RewriteEngine On 
    RewriteBase/
    

    # Block access to "hidden" directories whose names begin with a period. This 
    # includes directories used by version control systems such as Subversion or Git. 
    
     RewriteRule "(^|/)\." - [F] 
    

    # remove the www - Uncomment to activate 
    # 
    # RewriteCond %{HTTPS} !=on 
    # RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] 
    # RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 
    # 

    # Remove the trailing slash to paths without an extension 
    # Uncomment to activate 
    # 
    # RewriteRule ^(.*)/$ /$1 [R=301,L] 
    # 

    # Remove index.php 
    # Uses the "include method" 
    # http://expressionengine.com/wiki/Remove_index.php_From_URLs/#Include_List_Method 
    # 
    RewriteCond %{QUERY_STRING} !^(ACT=.*)$ [NC] 
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5})$ 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_URI} ^/(home|inc|publishers|sidebars|about|include-template|testing|advertisers|products|sitemap|style|ad-choices|social-bar|search|404||members|P[0-9]{2,8}) [NC] 
    RewriteRule (.*) /index.php/$1 [L] 

+0

po prostu dodaj '?' Po '$ 1' w ostatniej regule. 'RewriteRule (. *) /index.php/$1? [L] ' – Virendra

Odpowiedz

9

To usunąć łańcuch zapytania z URL

RewriteRule ^(.*) /index.php/$1? [L] #remove query string 

Nadzieja pomaga

2

Jestem trochę późno na odpowiedź, ale ponieważ szukałem podobnego zachowania, myślałem powinienem go udostępnić: możesz również dodać flagę do reguły przepisywania, aby usunąć ciąg zapytania; flaga jest [QSD] i pomaga uniknąć obejścia takiego jak ? na końcu ;-)

Here możesz znaleźć więcej informacji na temat tej flagi. Mam ochotę wskazać, że "Ta flaga jest dostępna w [Apache] w wersji 2.4.0 i późniejszej"

Powiązane problemy