StackOverflower
StackOverflower

Reputation: 1097

.htaccess Pretty URL rewrite inside a folder

I am trying to rewrite one of my urls to pretty urls but I can't seem to figure it out. Here is what I've tried

Current folder layout

-index.php
-/instagram
    -index.php
    -.htaccess

Inside the .htaccess I have put this code

RewriteEngine On
RewriteRule ^instagram/([^/]*)$ /instagram/?username=$1 [L]

My goal is to turn this url

http://example.com/instagram/?username=test1234

into this url

http://example.com/instagram/test1234

However, when I go to the second url in my browser it gives a 404 not found error. Any idea on how to fix this?

Upvotes: 1

Views: 1417

Answers (1)

anubhava
anubhava

Reputation: 785246

Place this code inside /instagram/.htaccess:

DirectoryIndex index.php
RewriteEngine On
RewriteBase /instagram/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?username=$1 [L,QSA]

Upvotes: 4

Related Questions