我如何通过.htacess重写以下内容的网址:
"http://www.domain.com/blog/"到"http://www.domain.com/blog.html"
和
"http://www.domain.com/general.php?code2"到"http://www.domain.com/this-is-ilas.html"
谢谢。
这是一个
简单的规则,mod_rewrite
:
通过httpd.conf
启用 mod_rewrite 和 .htaccess,然后将此代码放在.htaccess
DOCUMENT_ROOT
目录下:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^blog'.html$ /blog/ [L,NC]
RewriteRule ^this-is-ilas'.html$ /general.php?code2 [L,NC,QSA]
看看mod_rewrite。它将允许您更改 URL 向用户显示的方式,同时仍然在后端调用正确的脚本。这包括屏蔽任何 PHP URL 以显示为 .html
。一个可能的解决方案(尽管它可能需要一些工作;把它放在你的.htaccess
文件中):
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^ilas'.html$ general.php?=2
另请参阅:如何使用mod_rewrite规则重写.php以.html