简体   繁体   English

Apache Url重写或屏蔽以将扩展名删除为.php

[英]Apache Url Rewrite or mask to remove extensions as .php

I'm trying to url rewrite in my Apache but I'm not sure which one it is. 我正在尝试在我的Apache中进行URL重写,但不确定是哪一个。 For example if someone goes to www.example.com clicks on a tab in there, and by default it would be www.example.com/profile.php How can I rewrite it for www.example.com/profile / or better, www.example.com without /profile/ 例如,如果有人去www.example.com单击其中的一个选项卡,默认情况下它将是www.example.com/profile.php如何为www.example.com/profile重写它,或者更好,不带/profile/ www.example.com

RewriteEngine On

RewriteCond %{HTTP} on
RewriteRule ^/(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^/(.*)$ /$1.php [L,QSA]

RewriteCond %{HTTP_USER_AGENT} libwww-perl
RewriteRule ^ – [F]

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{QUERY_STRING} foo=(.*)
RewriteRule ^grab(.*) /search.php?query=%1

How can I rewrite it for www.example.com/profile/ or better, www.example.com without /profile/ 如何为www.example.com/profile/ 或更好的www.example.com(不带/ profile /)重写它

Your "better" approach is flawed. 您的“更好”方法是有缺陷的。 People like bookmarks. 人们喜欢书签。 Omitting the /profile/ from the URL will prevent link sharing and bookmarks. 从URL省略/profile/将阻止链接共享和书签。 Sites grow on easy link sharing. 网站通过轻松的链接共享而发展。

RewriteEngine On
RewriteRule ^([^\/]*)\/?$ $1.php [L,QSA]

You can test this rule here: http://htaccess.madewithlove.be/ 您可以在此处测试此规则: http : //htaccess.madewithlove.be/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM