我如何重写URL等

时间:2010-11-10 08:38:05

标签: apache .htaccess url-rewriting

我需要重写我的网址,例如

http://www.site.com/profile/ -> profile.php
http://www.site.com/settings/ -> settings.php

和profile和settinhs的另一个词是user.php

的链接

例如,

如果我推http://www.site.com/ giffary / - 它是指向user.php的链接?name = giffary

但是当我推http://www.site.com/profile/时 - 它是profile.php的链接,而不是user.php。

我怎么写.htaccess文件

谢谢你:)

1 个答案:

答案 0 :(得分:1)

显然,您需要使用mod_rewrite。我还没有测试过,但是这个配置应该工作:

RewriteEngine On
RewriteBase /

# Ignore URLs that point to files/directories that actually exist.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Special rewrites
RewriteRule ^/profile/?$ /profile.php [L]
RewriteRule ^/settings/?$ /settings.php [L]

# User profile rewrites
RewriteRule ^/([^/]+)/?$ /user.php?name=$1 [L]