1

I'm trying to do something rather simple here, but haven't been able to find the solution for it by searching here or Google - it must be that I don't know exactly what to search for.

Basically, I'm trying to do this with my .htaccess file:

www.mydomain.com/$ shows www.mydomain.com/$.php

and

www.mydomain.com/products/$ shows www.mydomain.com/products/$.php

Also, what is your favourite resource for learning how to code .htaccess files? I know my question is a simple one, and I would much like to be able to do things like this on my own from now on.

Thanks so much

4

1 回答 1

1

如果我理解正确,您只想在每个请求中添加一个“.php”。你可以使用

RewriteRule ^(.*)$ $1.php

为了实现这一点,即使用户请求 www.example.com/foo.php,它也会添加一个“.php”,所以你可能想要使用

RewriteRule ^(.*)(\.php)?$ $1.php

编辑:如果您想允许访问现有文件,例如 css 或 JavaScript 文件或图像,请使用 RewriteCond:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ $1.php [END]
于 2013-02-14T17:41:21.600 回答