【发布时间】:2015-03-04 12:52:29
【问题描述】:
我想为我的一个项目创建一个友好的 URL。目前我的网址是http://example.com/profile.php?user=someprofile,我想把它改成http://example.com/someprofile。我尝试了下面的 htaccess,但我的 CSS 和图像文件没有加载。
RewriteEngine on
RewriteCond $1 !^(profile\.php|assets|editor|css|js|scripts|images|img|media|xml|user_guide|robots\.txt|favicon\.ico)
RewriteRule ^g/([^/\.]+)/?$ profile.php?user=$1 [L]
<Files profile>
ForceType application/x-httpd-php
</Files>
我如何做到这一点?
【问题讨论】:
-
为什么你的模式中有
^g/? -
您的文件指令无关紧要。您不是在处理文件,而是在处理虚拟 url。
-
@anubhava ^g/ 给了我一个类似example.com/g/someprofile 的结果,我从另一个答案中选择了这个。
标签: php regex apache .htaccess friendly-url