htaccess的重写规则* .PHP到/ * /重写、规则、htaccess、PHP

由网友(冷暖自知)分享简介:我只是无法找到正确的解决方案,我需要什么,所以我希望有人能够帮助我在这里。I just can't find correct solution for what I need, so I hope someone will be able to help me here.我现在有这个文件,网址:I now hav...

我只是无法找到正确的解决方案,我需要什么,所以我希望有人能够帮助我在这里。

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]
阅读全文

相关推荐

最新文章