开发者

.htaccess mod_rewrite question

开发者 https://www.devze.com 2022-12-09 20:03 出处:网络
If I have a url http://example.com/pa开发者_开发技巧ge.php but I want the page to display when someone goes to http://example.com/page/

If I have a url http://example.com/pa开发者_开发技巧ge.php

but I want the page to display when someone goes to http://example.com/page/

how do I go about doing that?


Try this:

RewriteEngine on
RewriteRule ^([^/]+)/$ $1.php


I usually use something like this:

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule .* - [L]
RewriteRule ^$ index.php [L,QSA]
RewriteRule ^([^/\.]+)/?$ $1.php  [L,QSA]

</IfModule>

Note the question mark after the slash. You could add that to Gumbo's example to "test" for a trailing slash (so it can be there or not).

0

精彩评论

暂无评论...
验证码 换一张
取 消