【发布时间】:2012-02-19 19:44:58
【问题描述】:
目前我正在使用以下 HTACCESS 代码
RewriteEngine On
# Lose the www
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]
# Clean profile URLs
RewriteRule ^([a-zA-Z0-9_-]+)(/?)$ profile.php?user=$1
所以当我转到http://mysite.com/username 时,链接确实有效,我看到了个人资料。但我仍然可以使用http://mysite.com/profile.php?user=username。
我想要的是第二次被定向到http://mysite.com/username 的简短版本。
另一个问题是,当我浏览http://www.mysite.com/username 时,它会将url 重写为http://mysite.com/profile.php?user=username。
另外,对于某些文件夹,例如我的图像文件夹,我该如何避免这种情况?如果我转到图像文件夹,我会得到http://mysite.com/images/?user=images
另外,如果干净的 url 后面有一个斜线,页面的行为会很奇怪。
【问题讨论】: