【发布时间】:2013-10-20 00:24:05
【问题描述】:
在为我的问题寻找答案后,我仍然对此感到困惑。我正在开发一个允许用户创建个人资料的小型社交脚本,但我希望他们的个人资料 URL 简短。我编辑了 .htaccess 文件,它运行良好!
例如 www.site.com/username 重定向到 www.site.com/profile.php?user=username
但是,当您只是转到索引页面时。它显示 profile.php 但带有一个空的 GET 变量...
这是我的 .htaccess 代码
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ profile.php?name=$1 [QSA,L]
提前致谢!
【问题讨论】:
-
这个
.htaccess的位置是什么?profile.php and index.php文件在哪里? -
主目录(/public_html)。他们需要在不同的目录中吗?真的希望使它成为 www.site.com/username 而不是 www.site.com/profile/username
-
Are profile.php and index.php also in the main directory(/public_html).? -
是的,所有文件都在同一个目录下。
-
我会说:改用
^(.+)$。这要求至少存在 1 个字符。假设服务器已正确配置为在您请求目录时显示index.php等,它现在应该显示http://site.url/的索引页面。
标签: php apache .htaccess mod-rewrite redirect