1

可以帮助我吗?我想在我的网站的 url 中隐藏文件扩展名。

所以一个例子是 http://www.mysite.com/home.php http://www.mysite.com/control.php

而是显示为 http://www.mysite.com/home http://www.mysite.com/control

我一直在研究这个,发现这个代码似乎隐藏了 url 中的文件扩展名,但现在我的链接不起作用,我收到 404 错误。我认为我需要修改我的站点链接路径或类似的东西。

有人可以告诉我我需要做什么,这是我在.htaccess中使用的代码:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.]+\.php(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php$ http://www.mysite.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ http://www.mysite.com/$1/ [R=301,L]
4

2 回答 2

0

谷歌可以在堆栈之前提供帮助:)

   RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/]+)/$ $1.html 

# Forces a trailing slash to be added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

http://eisabainyo.net/weblog/2007/08/19/removing-file-extension-via-htaccess/ 另请查看 制作重写器删除 .php 扩展名?

于 2013-02-13T13:35:14.440 回答
0

如果要隐藏所有扩展名(不仅仅是 .php、.html),请使用:

Options +FollowSymLinks +MultiViews

在你的 httpd.conf 或 .htaccess

于 2013-02-13T13:38:12.127 回答