-1

I'm working on my .htaccess for a school project. I'm trying to rewrite my URL so it looks nicer. That is, you have localhost/website/public/profile/alex and not localhost/website/public/profile/index.php?username=alex.

I have this in my .htaccess file:

RewriteEngine On

RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$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=$1 [QSA,L]

Why is this not working? How can I make sure it will work?

Here is my file structure:

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
AddcitedToLearn
  • 398
  • 2
  • 18
  • what is your document root? When you start having all these extra folders it causes confusion. – Panama Jack Feb 16 '15 at 15:39
  • Do you have mod_rewrite enabled and told apache that he is allowed to parse .htaccess files? http://httpd.apache.org/docs/2.2/howto/htaccess.html - keep in mind, that on Apache 2.4 the syntax differs. – pmayer Feb 16 '15 at 15:39
  • My document root is all, then i have 2 sub folders a public where the user can do thing and a application with background information. – AddcitedToLearn Feb 16 '15 at 15:41
  • What do you mean all? I don't see an `all` folder in your list. – Panama Jack Feb 16 '15 at 15:43
  • document root- what terminology is even that. project root is GrouPlaylist, and under public is accessible part- the one where apache redirects to index file, this pretty common project setup, dude... – pankijs Feb 16 '15 at 15:43
  • Actually dude, no it's not. And it is referred to as "document root". http://httpd.apache.org/docs/current/mod/core.html#documentroot – Panama Jack Feb 16 '15 at 15:45
  • You say it's not working but what happens? Do you get an error or 404? I think it your rules that is wrong. – Panama Jack Feb 16 '15 at 15:47
  • @AlexdeBeer don't delete questions after getting answers – Alupotha Apr 04 '15 at 01:17

1 Answers1

0

in apache configuration make sure you have set AllowOverride to all

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

check this link for xampp, don't forget to restart xampp after editing http.conf .htaccess not working on localhost with XAMPP

Community
  • 1
  • 1
pankijs
  • 6,531
  • 3
  • 16
  • 13
  • well, does xampp have apache? yes it does, because "A" in xAmpp stands for apache, check in xampp config how to enable override all. – pankijs Feb 16 '15 at 15:44