url用.htaccess重写

时间:2011-01-28 17:49:28

标签: php .htaccess url-rewriting

我发现了一些关于网址重写的问题: .htaccess: Problem with URL rewriting.htaccess question - URL-rewriting

我试过他们的方法,但在我的情况下不起作用? 我看起来很简单:

http://example.org.uk/member/home.php?profile --> http://example.org.uk/member/home/profile/
http://example.org.uk/member/home.php?history --> http://example.org.uk/member/home/history/

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^home/([0-9][0-9])/$ /home.php?$1
RewriteRule ^/([^/]+).php$ /home.php?$1 [L]

任何人都被批评了吗?感谢

4 个答案:

答案 0 :(得分:4)

你的制作有点复杂,以下应该有效

http://example.org.uk/member/home.php?profile --> http://example.org.uk/member/home/profile/
http://example.org.uk/member/home.php?history --> http://example.org.uk/member/home/history/



RewriteRule ^/member/home/(.*)/ /home.php?$1 [L]

或更一般地

RewriteRule ^/(.*)/(.*)/(.*)/ /home.php?$3 [L]

答案 1 :(得分:0)

在RewriteRule中你有“^ /([^ /] +)。php $”,但你不想在URL中使用.php扩展名。从重写规则中删除.php。 这样的事情应该有效:

RewriteRule ^/member/home/.*$ /member/home.php?$1 [L]

答案 2 :(得分:0)

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/member/home/([a-zA-z0-9]+)/$ /member/home.php?$1 [L]

答案 3 :(得分:-1)

它仍会查找“.php”,因此您可以使用

RewriteRule ^/([^/]*)/$ home.php?$1