2012-04-18 4 views
2

Я использую этот файл htaccess на своем сайте для удаления index.php.Codeigniter htaccess не работает

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

Но этот файл не work.Rewriting включен в Apache module.Version из CodeIgniter используемого 2.0.1.

+0

Попробуйте удалить первый 'RewriteCond' и смените шаблон' RewriteRule' на '^ (?! index \ .php. *) $' – DaveRandom

+0

Вы хотите, чтобы я сделал это? RewriteEngine on RewriteRule^(. *) $^(?! index \ .php. *) $ – user1163513

+0

Нет, 'RewriteRule^(?! index \ .php. *) $ Index.php/$ 1 [L, QSA]' , И удалите 'RewriteCond $ 1!^(Index \ .php)'. – DaveRandom

ответ

3

Я проверил это без CodeIgniter, и она работает.

Я создаю папку под htdocs, называемую «demo». Я поставил ".htaccess" там с контентом + дополнительная линия (RewriteBase):

RewriteEngine on 
RewriteBase /demo/ 
# RewriteCond $1 !^(index\.php) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

Затем "index.php" ниже:

<?php 
echo $_SERVER['PATH_INFO']; 

Протестировано: http://localhost/demo/hello

Результат: /привет


Вещи, чтобы проверить:

  • Если вы положили «.htaccess» внутри папки, не забудьте добавить RewriteBase.
  • Убедитесь, что для вашего каталога включен FollowSymLinks. См. this link для получения дополнительной информации.
+0

Да, проблема в том, что я столкнулся с RewriteBase. Большое спасибо за решение. – user1163513

+0

Привет, Muhammad, я пробовал это, но на моем домене как-то это тоже не работает, я нахожусь на хостинге хостинга hostgator, если я использую это, то получаю 500 ошибок, другие мои домены не дают никакой ошибки, можете ли вы предложить, что будет причина? –

1

чтения this

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ /index.php/$1 [L] 
+0

Спасибо за ваш отзыв, но это не сработало для меня. – user1163513

+0

попробуйте это {RewriteEngine on RewriteRule^(.*) $ index.php/$ 1 [L]} –

0

Скопируйте это в ваш .htaccess

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase /CI_FOLDER/ 
#CI_FOLDER is the Location of your CI files. 

#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] 

#When your application folder isn't in the system folder 
#This snippet prevents user access to the application folder 
#Submitted by: Fabdrol 
#Rename 'application' to your applications folder name. 
RewriteCond %{REQUEST_URI} ^application.* 
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 
RewriteRule ^(.*)$ index.php?/$1 [L] 



</IfModule> 

<IfModule !mod_rewrite.c> 
# If we don't have mod_rewrite installed, all 404's 
# can be sent to index.php, and everything works as normal. 
# Submitted by: ElliotHaughin 

ErrorDocument 404 /index.php 
</IfModule> 
0

Поместите этот код в файл .htaccess CI_Folder

<IfModule mod_rewrite.c> 
    Options +FollowSymLinks 
    RewriteEngine on 
    RewriteBase /foldername/ 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ /foldername/index.php?/$1 [QSA,L] 
    </IfModule> 
    # BEGIN Expire headers <ifModule mod_expires.c> 
     ExpiresActive On 
     ExpiresDefault "access plus 5 seconds" 
     ExpiresByType image/x-icon "access plus 2592000 seconds" 
     ExpiresByType image/jpeg "access plus 2592000 seconds" 
     ExpiresByType image/png "access plus 2592000 seconds" 
     ExpiresByType image/gif "access plus 2592000 seconds" 
     ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds" 
     ExpiresByType text/css "access plus 604800 seconds" 
     ExpiresByType text/javascript "access plus 216000 seconds" 
     ExpiresByType application/javascript "access plus 216000 seconds" 
     ExpiresByType application/x-javascript "access plus 216000 seconds" 
     ExpiresByType text/html "access plus 600 seconds" 
     ExpiresByType application/xhtml+xml "access plus 600 seconds" </ifModule> 
    # END Expire headers 

    # BEGIN Cache-Control Headers <ifModule mod_headers.c> 
     <filesMatch "\.(ico|jpe?g|png|gif|swf)$"> 
      Header set Cache-Control "public" 
     </filesMatch> 
     <filesMatch "\.(css)$"> 
      Header set Cache-Control "public" 
     </filesMatch> 
     <filesMatch "\.(js)$"> 
      Header set Cache-Control "private" 
     </filesMatch> 
     <filesMatch "\.(x?html?|php)$"> 
      Header set Cache-Control "private, must-revalidate" 
     </filesMatch> </ifModule> 
    # END Cache-Control Headers 
    # BEGIN GZIP COMPRESSION <IfModule mod_gzip.c> mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image/.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* </IfModule> 
    # END GZIP COMPRESSION 
+0

Хотя этот код может ответить на вопрос, было бы лучше объяснить, как он решает проблему, не вводя других и почему ее использовать. Ответы только на код не полезны в долгосрочной перспективе. – JAL

+0

Большое вам спасибо - JAL –

0

Проверьте файл конфигурации сайта Apache. В Ubuntu 14.04 файл будет /etc/apache2/sites-available/site.conf

Изменение линии как этот

AllowOverride None 

К этому

AllowOverride All 

Перезапуск Apache для загрузки обновленный сайт .conf

sudo service apache2 restart 

Это решило это для меня.

Смежные вопросы