htaccess的重写规则* .PHP到/ * / [英] htaccess RewriteRule *.php to /*/
问题描述
我只是无法找到正确的解决方案,我需要什么,所以我希望有人能够帮助我在这里。
I just can't find correct solution for what I need, so I hope someone will be able to help me here.
我现在有这个文件,网址:
I now have website with this files:
/admin/
/images/
/js/
about.php
index.php
news.php
questions.php
所以,我的网址现在: www.mydomain.com/about.php www.mydomain.com/news.php ......
So my URLs now are: www.mydomain.com/about.php www.mydomain.com/news.php ...
我想有www.mydomain.com/about/,www.mydomain.com/news /,...
I would like to have www.mydomain.com/about/, www.mydomain.com/news/,...
我已经试过,我发现,但没有人如同它应该还是它搅乱别的东西了很多东西。
I have tried many things which I found but none of them works like it should or it messes something else up.
我到最近的是这样的:
RewriteRule about/ about.php
RewriteRule about about.php
但是,这也打乱了,如果我用一些形象code包含名称有关(例如图像/约-me.jpg) - 可能是因为第二个语句
But this also messes up if I use some image in code containing name about (example images/about-me.jpg) - probably because of second statement.
推荐答案
到的httpd.conf
启用了mod_rewrite和.htaccess,然后把这个code在< $ C C>的.htaccess $ DOCUMENT_ROOT
目录下:
Enable mod_rewrite and .htaccess through httpd.conf
and then put this code in your .htaccess
under DOCUMENT_ROOT
directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_FILENAME}.php [L]
这篇关于htaccess的重写规则* .PHP到/ * /的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!