我需要一些帮助来创建Htaccess

时间:2011-05-24 04:23:31

标签: php .htaccess

我需要隐藏我的网页的扩展名,并且还希望让用户将链接放在两个(下部和上部)的情况下:

示例:

文件名是demo.php

www.example.com/demo www.example.com/DEMO www.example.com/Demo

在LAMP服务器中运行PHP,无法访问php.ini,只能访问.htaccess

Actualy即时通讯使用这样的文件:

RewriteEngine On
RewriteBase /
RewriteRule ^/(OUTSOURCING|outsourcing|Outsourcing)$ outsourcing.php [NC,L]

我发现了这个错误:

Not Found

The requested URL /outsourcing was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

4 个答案:

答案 0 :(得分:2)

RewriteEngine On

RewriteBase /

www.example.com/DEMO www.example.com/Demo或www.example.com/DEMO/page2

RewriteRule ^/(DEMO|demo|Demo)/(.*)$ demo.php?=$1 [NC,L]

RewriteRule ^/(DEMO|demo|Demo)$ demo.php [NC,L]

RewriteRule ^/(D|d)emo$ demo.php [NC,L]

或将任何www.example.com/DeMo www.example.com/bob传递给demo.php

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ demo.php [NC,L]

您可能想要测试您是否允许.htaccess RewriteRule /*$ http://google.com [R][L]

答案 1 :(得分:1)

这是使用不区分大小写的方法

的好方法

编辑:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ${lc:$1}.php [NC]

这样输入的任何内容都将被重定向到php文件。

编辑:这样你的js和css文件仍然可以运行

答案 2 :(得分:0)

RewriteRule ^/[Dd][Ee][Mm][Oo]/?(.*)$ demo.php [NC,L]

会将“演示”的任何大写重定向到demo.php

答案 3 :(得分:0)

首先在<VirtualHost>部分或httpd.conf文件末尾添加此行(在.htaccess中启用lc函数供以后使用):

RewriteMap lc int:tolower

然后在.htaccess文件中有这些规则:

Options +FollowSymlinks -MultiViews
RewriteEngine on

RewriteCond %{THE_REQUEST} ^GET\s.+\.php [NC]
RewriteRule ^(.+)\.php$ /$1 [NE,R=301,L,NC]

RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteCond ${lc:%{REQUEST_FILENAME}}.php -f
RewriteRule . ${lc:%{REQUEST_URI}}.php [L]
  • .htaccess中的第一条规则是通过将/index.php设为/index

  • 来执行外部重定向
  • .htaccess中的第二条规则是通过降低URI来将/INDEX的URI设置为/index.php来执行内部重定向。假设你有文件名index.php实际存在。

这样您就可以随时编写没有.php扩展名的网址。

相关问题