How to make pretty seo urls via .htaccess in Apache

I will keep this post very short and sweet.

You can easily remove file extensions, in this case ‘.php’ from your urls, so that your urls are easy to remember, provide top SEO results and value, look pretty without file extensions, represent your architecture and are easy to change or redirect?

Pretty urls with no .php extension
{code type=html}

www.mysite.com/subsection/
www.mysite.com/subsection/page
{/code}

Ugly urls with extensions
{code type=html}

www.mysite.com/subsection/index.php
www.mysite.com/subsection/page.php
{/code}

Quite simply this is the only way you should ever be serving content. In your .htaccess (the one in the root) of your website copy and paste the below into it. Or just create one and add the following code.

.htaccess extension removal
{code type=html}
Options +FollowSymlinks
RewriteEngine On

# Pretty url’s
# /page.php == /page
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
{/code}

Now all your urls are pretty, optimised and simple to remember.

Site architecture examples

{code type=html}

www.mysite.com/subsection/


root\subsection\index.php
{/code}

{code type=html}

www.mysite.com/subpage


root\subpage.php
{/code}

{code type=html}

www.mysite.com/subsection/page


root\subsection\page.php
{/code}

Enjoy!

Comments are closed.