Aihsan Majeed Aihsan Majeed - 11 months ago 46
PHP Question

simple URL rewrite using htaccess

I'm looking to rewrite my current directory structure to create a friendly URL.

Directory Structure

Root Folder

  • includes

  • images

  • css

  • js

  • partials

  • pages

  • Page 1

    • index.php

  • Page 2

  • Page 3

  • Page 4

So the current URL path is, but what i would like is to have is So the website can be placed Bitbucket to enable versioning.

Any help or links are hugely appreciated.



You can use the following rule in root/.htaccess :

RewriteEngine on
#1) Redirect from "/page/foobar" to "/foobar" #
RewriteCond %{THE_REQUEST} /page/(.+)\sHTTP [NC]
RewriteRule ^ /%1 [L,R]
#2)internally redirect "/foobar" to "/page/foobar" #
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /page/$1 [NC,L]

This will internally redirect /page to /page/page .