2015-12-29 127 views
1

我需要將以下頁面重定向到它們的.php版本。.htaccess不會重定向到.php文件

http://www.kgolf360.com/about 
http://www.kgolf360.com/news 
http://www.kgolf360.com/junior-performance-programs 
http://www.kgolf360.com/before-after 
http://www.kgolf360.com/book-lesson 
http://www.kgolf360.com/family-performance-programs 
http://www.kgolf360.com/technology 
http://www.kgolf360.com/adult-performance-programs 

例如,我需要重定向

http://www.kgolf360.com/about 

http://www.kgolf360.com/about.php 

我所做的是通過添加以下修改我的.htaccess文件:

Redirect 301 /about http://www.kgolf360.com/about.php 

但它給了我一個404錯誤。你可以看到它,如果你去http://www.kgolf360.com/about

是否有可能我需要配置別的東西,使其工作?如果是這樣,我需要做些什麼才能正確地重定向URL?

這是我的.htaccess文件的內容:

rewriteengine on 
rewritecond %{HTTP_HOST} ^www.kgolf360.com$ [OR] 
rewritecond %{HTTP_HOST} ^kgolf360.com$ 
rewriterule ^about$ "http\:\/\/kgolf360\.com\/about\.php" [R=301,L] #5682a68c22ecf 
rewritecond %{HTTP_HOST} ^kgolf360.com$ 
rewriterule ^(.*)$ "http\:\/\/www\.kgolf360\.com\/$1" [R=301,L] #567eeb84dcae2 


# The following will allow you to use URLs such as the following: 
# 
# example.com/anything 
# example.com/anything/ 
# 
# Which will actually serve files such as the following: 
# 
# example.com/anything.html 
# example.com/anything.php 
# 
# But *only if they exist*, otherwise it will report the usual 404 error. 
Options +FollowSymLinks 
# Redirect to HTML if it exists. 
# e.g. example.com/foo will display the contents of example.com/foo.html 
# Redirect to PHP if it exists. 
# e.g. example.com/foo will display the contents of example.com/foo.php 
rewritecond %{REQUEST_FILENAME} !-f 
rewritecond %{REQUEST_FILENAME} !-d 
rewritecond %{REQUEST_FILENAME}.html -f 
rewriterule ^(.+)$ $1.html [L,QSA] 
rewritecond %{REQUEST_FILENAME} !-f 
rewritecond %{REQUEST_FILENAME} !-d 
rewritecond %{REQUEST_FILENAME}.php -f 
rewriterule ^(.+)$ $1.php [L,QSA] 

#Redirect all non-php URLs to their php versions 

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.php [NC,L] 

難道你們看到我現在在FLE內容有任何問題?

+0

您是否啓用了Apache的mod_alias?如果不是的話,'Redirect'指令將被忽略,並且/ about將返回一個404. – BareNakedCoder

+0

也會檢查mod_rewrite是否被啓用並且你的服務器被配置爲使用它。這聽起來很愚蠢,但這多次是問題的根源。 – Gogol

+0

這可能也有幫助http://stackoverflow.com/questions/17868819/apache-mod-rewrite-not-working-with-htaccess-file – Gogol

回答

3

由於您使用的是Godaddy,因此您需要使用Options +MultiViews。因此,請嘗試下面的代碼:

Options +MultiViews 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.php [NC,L] 
+0

我已經添加了你推薦的代碼塊,但它並沒有做到這一點。請看看我更新的問題。我添加了我的.htaccess文件的內容。也許文件中存在某種衝突? –

+0

看起來不錯,但描述它怎麼樣? :) upvoted雖然 – Gogol

+0

嗯,這是我的客戶的.htacccess文件(由他的網頁開發人員完成)。我只是一個搜索引擎優化的人,試圖找出爲什麼我不能重定向標準方式:)我還有希望嗎? :) –