Codeigniter Seo Url With Htaccess

- 1 answer

I`m using Codeigniter 3.0.3

I need to use link like this

I have this htaccess

# Disable file indexing
Options -Indexes
# Follow symbolic links.
Options +FollowSymLinks

php_value upload_max_filesize 16M
php_value post_max_size 16M
php_value max_input_vars 1000000

# Compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# adding type for .woff2:
AddType application/x-font-woff2 .woff2
# adding type for .woff:
AddType application/x-font-woff .woff
AddType application/ .docm
AddType application/vnd.openxmlformats-officedocument.wordprocessingml.document docx
AddType application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx
AddType application/ potm
AddType application/vnd.openxmlformats-officedocument.presentationml.template potx
AddType application/ ppam
AddType application/ ppsm
AddType application/vnd.openxmlformats-officedocument.presentationml.slideshow ppsx
AddType application/ pptm
AddType application/vnd.openxmlformats-officedocument.presentationml.presentation pptx
AddType application/ xlam
AddType application/ xlsb
AddType application/ xlsm
AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
AddType application/ xltm

# Prevent viewing of htaccess file.
<Files .htaccess>
    order allow,deny
    deny from all

<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /

    # Set REQUEST_SCHEME (standard environment variable in Apache 2.4)
    RewriteCond %{HTTPS} off
    RewriteRule .* - [E=REQUEST_SCHEME:http]

    RewriteCond %{HTTPS} on
    RewriteRule .* - [E=REQUEST_SCHEME:https]

    # Check for POST Submission
    RewriteCond %{REQUEST_METHOD} !^POST$

    # Redirect to domain with www.
    RewriteCond %{HTTPS} off
    RewriteCond %{SERVER_PORT} 80
    RewriteCond %{SERVER_NAME} !^www\. [NC]
    RewriteRule .* http://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

    # Redirect to domain with www.
    RewriteCond %{HTTPS} on
    RewriteCond %{SERVER_PORT} 443
    RewriteCond %{SERVER_NAME} !^www\. [NC]
    RewriteRule .* https://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

    ### Canonicalize codeigniter URLs

    # If your default controller is something other than
    # "welcome" you should probably change this
    RewriteRule ^(index(/index)?|index(\.php)?)/?$ / [L,R=301]
    RewriteRule ^(.*)/index/?$ $1 [L,R=301]

    # Removes trailing slashes (prevents SEO duplicate content issues)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ $1 [L,R=301]

    # Removes access to the system folder by users.
    # Additionally this will allow you to create a System.php controller,
    # previously this would not have been possible.
    # 'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php/$1 [L]

    # Checks to see if the user is attempting to access a valid file,
    # such as an image or css document, if this isn't true it sends the
    # request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.*)$ index.php/$1 [L]

<IfModule !mod_rewrite.c>
    # Without mod_rewrite, route 404's to the front controller
    ErrorDocument 404 /index.php

now I need to owerwrite - to _ so the real url will be like this


how can I do this?



In your config/routes.php file:

You can define this URL:



$route['my-controller/my-function/(:any)/(:any)/(:any)'] = "my_controller/my_function/$1/$2/$3";

Here, these 3 (:any) means your three params rest url you can use any thing do you.

One more example with simple route:

$route['about-us'] = "aboutus";

Here aboutus is my controller name, and i want to access it as


Than i can use like that.

Side Note: You can get URL values by using uri->segment().

User Guide