Search code examples
.htaccesslocalhostmamp

.htaccess not working on localhost


My completed code in my only .htaccess file:

Options FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteRule blue-world.pl/([a-z]+)(?:/([a-z]+))? index.php?nav=$1#$2

I need to redirect blue-world.pl/name/name2 to blue-world.pl?nav=name#name2. How to do this to make it working BOTH: localhost and server.

When in MAMP i try to type: localhost/scregal.blue-world.pl/title i see:

The requested URL /scregal.blue-world.pl/title was not found on this server.

Below is my file hierarchy in localhost:

scregal.blue-world.pl
    - .htaccess
    - index.php -> var_dump($_GET)

In the httpd.conf there are following lines:

LoadModule rewrite_module modules/mod_rewrite.so

AllowOverride All

Solution

  • You can use this rule:

    Options FollowSymLinks
    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)(?:/([^/]+))?/?$ index.php?nav=$1#$2 [L,QSA,NC]