2015-12-29 94 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文件(由他的网页开发人员完成)。我只是一个搜索引擎优化的人,试图找出为什么我不能重定向标准方式:)我还有希望吗? :) –