这是我的htaccess
RewriteEngine On
AddType application/x-httpd-php53 .php
SetEnv TZ Asia/Manila
# If the user types just “admin”.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin$ admin\.php [L,QSA]
# If the user enter in any admin section, like “admin/section”.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin\/(.*)$ admin\.php/$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !index\.php
RewriteRule ^(.*)$ index.php/$1 [L]
它在localhost上工作正常但是当我迁移到实时服务器时会发生这种情况
答案 0 :(得分:0)
我将假设你试图摆脱你的codeigniter网站的所有网址中的'index.php'。这是我目前使用的.htaccess文件,它工作正常。例如,如果我的网站网址是
www.test.com/index.php/home
它会以
出现www.test.com/home
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
如果您希望在网址中使用“admin”一词,请按以下方式编写。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
RewriteRule .* admin.php/$0 [PT,L]
编辑:
您还提到了在您的实时服务器上无法使用的更改。您的实时Web服务器是否在Windows上运行?
如果是这样,您需要在网站的根目录中使用“web.config”文件。这应该是它的样子。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to index.php">
<match url="index.php|robots.txt|images|test.php" />
<action type="None" />
</rule>
<rule name="Rewrite CI Index">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html|pdf|xls|xlsx" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>