如何使用Apache mod_rewrite从地址栏中删除脚本名称

时间:2014-03-19 08:44:29

标签: php apache .htaccess mod-rewrite

我有三个域名,比如frontend.com,platform.com,userpanel.com。其中每一个都指向我的服务器机器,其中index.php脚本重定向到frontend.php,platform.php,userpanel.php。域和脚本之间的关联可以更改,它存储在数据库中,index.php每次都会检查它。

工作正常。

我想从浏览器地址栏中删除脚本名称,以获取frontend.com而不是frontend.com/frontend.php,platform.com而不是platform.com/platform.php和userpanel.com而不是userpanel。 COM / userpanel.php。如何使用Apache mod_rewrite实现它?

1 个答案:

答案 0 :(得分:1)

您可以在DocumentRoot/.htaccess

中使用此规则
RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC]    
RewriteCond %{HTTP_HOST} ^([^.]+)\. [NC]
RewriteRule ^$ /%1.php [L]
相关问题