2014-02-24 51 views
0

我已經花費了數不多的時間試圖開發一個好的.htaccess爲SEO目的提供不擴展的URL。幾乎我看到的每個現代網站都有無擴展名的網址,並且是一個相當新的網站,我希望採用這種方法。.htaccess不擴展url和301重定向循環

我已經能夠成功地使用.htaccess將網站轉換爲無擴展名。例如:

example.com/page.php將成爲example.com/page1在URL

但是,現有的是同一位置的頁面(如contact.php頁)會做一個循環時做301重定向。因此,例如,以便搜索引擎不認爲/contact.php和/ contact是兩個不同的頁面,現有索引/contact.php具有301重定向到/ contact

但是,/ contact url在後臺從/contact.php中提取數據,並且.htaccess知道這一點,然後想要將301重定向再次應用於/contact.php後面的/ contact以導致循環。我無法弄清楚如何阻止這一點。

底線是我想從/contact.php重定向301到/ contact /中的/ contact,反映/contact.php物理文件的內容。

這是我的.htaccess工作正常,除了有301重定向的網頁。

我也有興趣在任何其他問題,您可以在我的.htaccess :)

.htaccess 
    Options -MultiViews 
    Options +FollowSymLinks 
    RewriteEngine on 
    RewriteBase/


    ## 301 Redirects 
     # 301 Redirect 1 
     RewriteCond %{QUERY_STRING} ^$ 
     RewriteRule ^contact\.php$ /contact? [R=301,NE,NC,L] 


    ## Exclude appropriate directories from rewrite rules ^(blogsphere) 
     RewriteRule ^(blogsphere) - [L] 

    ## Unless directory, remove trailing slash 
     # If requested URL ending with slash does not resolve to an existing directory 
      RewriteCond %{REQUEST_FILENAME} !-d 
     # Externally redirect to remove trailing slash 
      RewriteRule ^(.+)/$ $1 [QSA,L] 

    ## Redirect external .php requests to extensionless url 
     # Any type of POST/GET should be a condition so that it doesnt rewrite without that data (end fileames in submissionscript) 
      RewriteCond %{REQUEST_URI} !^/([a-z-]+)\-(submissionscript)(.*)$ 
     #Request has to end in .php 
      RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/ 
      RewriteRule ^(.+)\.php$ $1$2 [QSA,L] 

    ## If it is not a directory then internal resolve request to end with .php for extensionless php urls (/page will internally resolve to /page.php) 
     RewriteCond %{REQUEST_FILENAME} !-d 
     RewriteRule ^((?!(\.|\.php)).)*$ $0.php [QSA,L] 

回答

0

有像這樣看:

Options -MultiViews 
Options +FollowSymLinks 
RewriteEngine on 
RewriteBase/

# skip blogsphere directory for rewrite 
RewriteRule ^(blogsphere) - [L] 

## Unless directory, remove trailing slash 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s] 
RewriteRule ^(.+?)/$ $1 [R=301,L] 

# remove .php extension from URL - external redirect 
RewriteCond %{REQUEST_URI} !^/([a-z-]+)-(submissionscript)(.*)$ 
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC] 
RewriteRule^%1 [R=301,L,NE] 

# internally rewrite a file to file.php 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC] 
RewriteRule ^(.+?)/?$ $1.php [L] 
+0

反正你可以發表評論易行項目的學習我和其他人? – user3330299

+0

確定添加我的評論,請檢查。 – anubhava