我怎样才能让 .htaccess 工作?

How can I get .htaccess to work?

我正在为一个学校项目开发我的 .htaccess。我正在尝试重写 URL 以使其看起来更好。也就是说,您有 localhost/website/public/profile/alex 而不是 localhost/website/public/profile/index.php?username=alex

我的 .htaccess 文件中有这个:

RewriteEngine On

RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/ [R=301,L]

RewriteCond %{HTTP_HOST} ^localhost/website/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^public/profile/?(.*)$ public/profile/index.php?username= [QSA,L]

为什么这不起作用?我怎样才能确保它能正常工作?

这是我的文件结构:

website/
    application/
    public/
        css/
        font/
        img/
        js/
        login/
        player/
        playlist/
        profile/
            const.php
            index.php
        register/
        const.php
        testplayer.php
    .htaccess
    website.sql
    index.php
    README.md

在 apache 配置中,确保您已将 AllowOverride 设置为全部

http://httpd.apache.org/docs/2.2/howto/htaccess.html

为 xampp 检查此 link,不要忘记在编辑 http.conf 后重新启动 xampp .htaccess not working on localhost with XAMPP