简体   繁体   中英

htaccess rewriterule not working in codeigniter

Here I am trying to remove index.php from URL in my codeigniter application.

For that, i write .htaccess file like this:

# Turn on URL rewriting
RewriteEngine On

# Installation directory
# RewriteBase /projectname/

# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
    Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php [PT]

It is working in xx.xx.xx.xxx server and mydomain.com. Here i tried to make a same copy to another server yy.yy.yy.yyy. In this, rewrite URL is not working. If i use 'yy.yy.yy.yyy/index.php/login', its working correctly. But 'yy.yy.yy.yyy/login', it throws me 'The requested URL /projectname/login was not found on this server.' error.

For your main directory .htaccess try this and then remove index.php from config.php

Options +FollowSymLinks
Options -Indexes

<FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
    Order deny,allow
    Deny from all
</FilesMatch>

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

Do not touch the .htaccess files in applications directory's.

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