简体   繁体   中英

how to skip index.php and method name in url of codeigniter 1.7.2?

I am newbie with Codeigniter 1.7.2. I want to skip index.php and method name of Site URL. But I don't know how to skip them. My site url looks like -

http://localhost/mysadagi_voicetongues/index.php/deal_bazaar/PrivilegeDealsbazaar

So I want skip index.php and PrivilegeDealsbazaar from url.

Please give solution to fix this issue.

Thanks

I forget to tell. open your config file: application/config/config.php and change this line

$config['index_page'] = “index.php”

To

$config['index_page'] = “”

Create a .htaccess file in the root of your app so

  • system
  • application
  • assets
  • .htaccess

To delete the index.php from your url use this .htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^LoginTut.*
RewriteRule ^(.*)$ index.php?/$1 [L]

RewriteCond $1 !^(index\.php|images|table-images|js|robots\.txt|css|captcha)

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
 ErrorDocument 404 index.php
</IfModule>

It's not a very good idea to hide the controller name because you will get a lot of problems when routing and linking to other functions.

Hope it helps!

Use latest version on CI 2.1.3 You can use .htaccess to hide index.php from URL. You can use following .htaccess

<IfModule mod_rewrite.c>
   RewriteEngine On
    #AddHandler application/x-httpd-php5 .php
    RewriteBase /projectforlder/

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

</IfModule>

<IfModule !mod_rewrite.c>
   ErrorDocument 404 /index.php
</IfModule>

You can not access your controller without specifying it in URL.

you can do this in 3 steps:

1) Create .htacess file in parallel to application holder and just copy past the following code:

RewriteEngine On
RewriteBase /CodeIgniter/       /* this will be your prj name. Change it as per your directory structure*/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

2) Change $config['index_page'] to blank in config.php in application folder as below:

$config['index_page'] = '';

3) Enable "rewrite_module" of apache.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM