2012-11-28 45 views
3

我有一个URL重写,删除文件扩展名。它使用.html页面,但它给了我一个“404页面未找到”的错误.php文件。URL重写工作.html但不是.php

这里是我的全.htaccess文件

# 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 
RewriteEngine On 

rewritecond %{HTTP_HOST} ^inaflashgraphics.com$ 
rewriterule^"http\:\/\/www\.inaflashgraphics\.com\/" [R=301,L] #4e2f2fa615667 

# Remove trailing slashes. 
# e.g. example.com/foo/ will redirect to example.com/foo 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)/$ /$1 [R=permanent,QSA] 

# Redirect to HTML if it exists. 
# e.g. example.com/foo will display the contents of example.com/foo.html 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteRule ^(.+)$ $1.html [L,QSA] 

# 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}.php -f 
RewriteRule ^(.+)$ $1.php [L,QSA] 

我到底做错了什么?

+0

我建议添加一个RewriteLog并将RewriteLogLevel设置为5,这样您可以逐步查看它正在做什么。 – GarethL

+0

不知道该怎么做 – jardane

+0

在“RewriteEngine On”之后,在单独的行上添加以下内容:“RewriteLog/path/to/your/new/log”和“RewriteLogLevel 5”。这将在您指定的路径中创建一个日志文件,并且会在尝试确定要提供的正确文件时写入重写引擎所做的每一个步骤。很明显,当你解决问题的时候记得去掉这个! – GarethL

回答

0

你可以试试:

RewriteCond %{HTTP_HOST} ^www\.inaflashgraphics\.com 
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP 
RewriteRule (.*)\.php$ $1 [R=301] 
+0

nope,没有工作 – jardane

+0

试着把这个前面的html位 – boruch

+0

刚试过,没有工作 – jardane

0

我想通了,该代码为我工作。

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 

rewritecond %{HTTP_HOST} ^inaflashgraphics.com$ 
rewriterule^"http\:\/\/www\.inaflashgraphics\.com\/" [R=301,L] 

RewriteBase/

## hide .php extension 
# To externally redirect /dir/foo.php to /dir/foo 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] 
RewriteRule^%1 [R,L,NC] 

## To internally redirect /dir/foo to /dir/foo.php 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule^%{REQUEST_URI}.php [L] 

# Redirect to HTML if it exists. 
# e.g. example.com/foo will display the contents of example.com/foo.html 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteRule ^(.+)$ $1.html [L,QSA]