Search code examples
apache.htaccessmod-rewrite

How to remove part of URl with .htaccess?


Currently, I have 20+ URLs on my site in this format

http://www.example.net/content/index/mission

I want to remove /content/index from all URLs, so they should look something like this

http://www.example.net/mission

In other words, I would always remove /content/index from the URL. I'm sure it's really straightforward, but I'm not very experienced with Apache.


Solution

  • You would need the rewrite module of Apache: mod_rewrite.

    Then do something like this:

    RewriteEngine on 
    RewriteRule ^content/index/(.*)$ $1
    

    Here is the official documentation of mod_rewrite: click