Rewriting parameters to use slash - htaccess

July 13, 2016 229 views
Apache PHP Ubuntu

So on our site, we have dynamic pages which will fetch info on what is requested. For the sake of making sense, I'll use our blog as an example.

So I have, which will fetch a certain article from the data base. After looking around for this answer, I couldn't figure anything out. I want the url to look like Using the help of Google, I came up with this:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /blog
RewriteRule ^([^/]+)/([^/]+)$ article.php?id=$1

Since both blog and article are actual pages, I couldn't have arguments for what page I want specifically. Any help on how to achieve this will be appreciated.

1 Answer

What you are looking for is called SEO friendly urls. I found few articles that should help you. :)

  • Okay so I mixed some resources from both articles, and am still getting errors.

    Here's what I have for my .htaccess:
    Options +FollowSymLinks -MultiViews
    RewriteEngine On
    RewriteRule ^blog/article/([0-9]+)/?$ blog/article.php?id=$1 [NC,L]

    It's in the /blog directory of

    So when I go to, I want the page to deliver what shows; not an error page.

    • Make sure .htaccess is enabled. In your Apache virtualhost file. By default this file is /etc/apache2/sites-available/000-default.conf. Add the code below to this file:

      # You may want to change the directory to the directory you have your .htaccess file.  
      # But this should be fine.
      <Directory />
          Options FollowSymLinks
          AllowOverride All

      Now enable the apache rewrite module by running the command:

      sudo a2enmod rewrite
      sudo service apache2 restart

      Hope this resolves your issue!

Have another answer? Share your knowledge.