【问题标题】:make example.com/user/Bob go to profile.php?user=Bob让 example.com/user/Bob 转到 profile.php?user=Bob
【发布时间】:2011-04-23 04:20:12
【问题描述】:

我当前的http访问文件是

# Pound sign comments a line out

# Disallow viewing of htaccess files
<Files .htaccess>
order allow,deny
deny from all
</Files>

Options +FollowSymLinks
RewriteEngine On

# enable hiding php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php 

现在它只是隐藏 .php,我仍然想隐藏 .php 但允许网站/用户/用户名

【问题讨论】:

    标签: apache .htaccess mod-rewrite url-rewriting apache2


    【解决方案1】:

    给你:

    RewriteEngine On
    RewriteRule ^user/(.*) profile.php?user=$1 [L]
    

    【讨论】:

    • “不工作”到底是什么意思。你有错误吗?什么样的错误?我在上面复制了你的 .htaccess 文件,并将我发布的 RewriteRule 添加到它的末尾,它对我有用。
    • “糟糕!此链接似乎已损坏。”我运行了 a2enmod rewrite 然后 /etc/init.d/apache2 restart 所以我知道 mod rewrite 是打开的......
    • 你能检查你的 apache 错误日志吗?那应该提供更多细节。听起来你在 Ubuntu 上,所以它可能在 /var/log/apache2/error.log 中。
    猜你喜欢
    • 2023-03-13
    • 2012-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-09
    • 2018-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多