14

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.

Coozywana
  • 27
  • 10
Salman Aslam
  • 761
  • 1
  • 11
  • 20
  • 1
    possible duplicate of [How to remove Controller and function name from URL in CodeIgnitor](http://stackoverflow.com/questions/7603845/how-to-remove-controller-and-function-name-from-url-in-codeignitor) – Paul Dixon Oct 10 '11 at 10:11

5 Answers5

19

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

janoliver
  • 7,744
  • 14
  • 60
  • 103
  • I tried it, but it is not working. I am working with CI. Can you suggest some more solutions? – Salman Aslam Oct 10 '11 at 08:57
  • I can't test it here right now. mod_rewrite is a pretty popular topic and you will find many information with google. Check if mod_rewrite is enabled and loaded with apache and try to find the correct pattern to work with. – janoliver Oct 10 '11 at 09:04
  • I can confirm that it's working, thanks @janoliver! – eldorjon Jun 29 '23 at 06:19
2
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/removedstring/
RewriteRule ^removedstring/(.*)$ https://www.domain.eu/$1 [L,NC,R=301]
Robert G.
  • 317
  • 2
  • 8
1

I'm going to guess you already have some rewrite rules in place for URLs like http://www.example.net/content/index/mission

You need to find these rules and add a new one which uses a similar structure but 'hard codes' the content/index parts, for example, suppose the existing one was

RewriteRule ^content/(.*)/(.*)$ /content.php?param1=$1&param2=$2 [L,qsa]

You'd want to make a new rule to pick up /mission and rewrite it in a similar way, but before the existing rule kicks in, e.g.

RewriteRule ^mission$ /content.php?param1=index&param2=mission [L,qsa]
RewriteRule ^content/(.*)/(.*)$ /content.php?param1=$1&param2=$2 [L,qsa]

These are just examples - it will really depend on what your existing rules are.

Paul Dixon
  • 295,876
  • 54
  • 310
  • 348
0
  # Get rid of index.php
  RewriteCond %{REQUEST_URI} /index\.php
  RewriteRule (.*) index.php?rewrite=2 [L,QSA]

  # Rewrite all directory-looking urls
  RewriteCond %{REQUEST_URI} /$
  RewriteRule (.*) index.php?rewrite=1 [L,QSA]

Or just add index.html depending on whatever extention you want to remove and MOD_REWRITE is required on Apache for this to work. Thank you.

0

I also have a script I wrote that you put on your server then browse to it via internet browser and it can confirm if you have mod_rewrite on your server. The way I showed you works 100% as long as mod_rewrite is enabled

  • I have already remove index.php from URL through .htaccess . So, i guess mod_rewrite is enabled. But now nothing is working for removal of content/index – Salman Aslam Oct 10 '11 at 09:31