Apache 如何重写URL,例如

Apache 如何重写URL,例如,apache,.htaccess,url-rewriting,Apache,.htaccess,Url Rewriting,我需要重写我的web URL,例如 http://www.site.com/profile/ -> profile.php http://www.site.com/settings/ -> settings.php profile和settinhs的另一个词是link to user.php 例如 如果我推送giffary/-它是指向user.php的链接?name=giffary 但是当我推送时,它是指向profile.php的链接,而不是user.php 如何写入.htacce

我需要重写我的web URL,例如

http://www.site.com/profile/ -> profile.php
http://www.site.com/settings/ -> settings.php
profile和settinhs的另一个词是link to user.php

例如

如果我推送giffary/-它是指向user.php的链接?name=giffary

但是当我推送时,它是指向profile.php的链接,而不是user.php

如何写入.htaccess文件


谢谢:)

显然,您需要使用
mod\u rewrite
来完成此操作。我尚未对其进行测试,但此配置应能正常工作:


作为补充说明,此配置将/profile和/profile/映射到profile.php。事实上,尾随斜杠在所有情况下都是可选的。如果需要,请删除?在RewriteRule指令中的/之后。每个last of语句中的[L]是什么?这意味着“last”--一旦任何规则匹配,它将停止处理任何进一步的规则。
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]