Rewriting parameters to use slash - htaccess

Posted July 13, 2016 17.3k views

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.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
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!