2013-03-21 54 views
1

我坚持使用.htaccess修改,需要一点帮助。
首先,这里是我的htaccess中的内容。htaccess重定向和重写从PHP到HTML

RewriteEngine on 
RewriteRule ^(.*)\.html$ $1.php [nc] 

例如,我创建了名为test.php的文件并上传到我的服务器。

我希望我的服务器的行为如此。

http://example.com/test/test.html -> http://example.com/test/test.html(as it is) 
http://example.com/test/test.php -> http://example.com/test/test.html 

但与的.htaccess我有现在, 我仍然有两个.PHP和.html这可以被认为是搜索引擎爬虫像谷歌机器人文件复制(是不是?)。

任何帮助表示赞赏。

回答

1

试试这个的.htaccess代码

# Enable Rewrite Engine 
RewriteEngine on 

#Create friendly URL 
RewriteRule ^test/(.*)\.html$ test/$1\.php [L] 

OR

RewriteCond %{REQUEST_URI} ^(.*)\.php$ 
RewriteRule ^(.*) /$1.html [L] 

OR

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

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

感谢Sumit快速回复。 但我的文件名可以是任何东西。像index.php,company.php,mission.php,access.php等等......所以更好地使用正则表达式吧? – norixxx 2013-03-21 10:45:22

+0

@norixxx检查我更新的'RewriteRule'为多页 – 2013-03-21 10:48:54

+0

如果这不起作用检查我的“OR”部分的答案,这将反抗工作 – 2013-03-21 10:55:34

1

这是阿帕奇”的.htaccess'的配置文件,如果你还在想要配置然后ch安格

RewriteEngine叙述上

我希望这项工作

+0

谢谢。我在我的htaccess的第一行写了'RewriteEngine'。仍然无法正常工作。 – norixxx 2013-03-21 11:17:40

1

您可以在根目录下试试这一个.htaccess文件:

Options +FollowSymLinks -MultiViews 
RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_URI} !\.html    [NC] 
RewriteRule ^([^/]+)/([^.]+)\.php /$1/$2.html [R=301,NC,L] 

对于沉默的映射,替换[R = 301,NC ,L]与[NC,L]