我需要重写我的网址,例如
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文件
谢谢你:)
答案 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]