2013-01-12 62 views
-1

我正在使用PHP 5.3.5的Wamp和htaccess已启用。删除'index.php?'使用.htaccess

我面临的问题是我需要像这样的东西http://localhost/abc/aboutus

现在实际的URL是这样的http://localhost/abc/index.php?aboutus

我尝试下面的代码:

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

并尝试使用它像http://localhost/abc/aboutus,但它并不适用于工作。但是当我尝试像http://localhost/abc/?aboutus

它工作正常,但我实际上想从URL中删除?。谁能告诉我我错在哪里?

回答

0

您必须考虑规则中的/abc/ URI基数。因此,如果htaccess文件是在你的文档根目录,该规则需要这个样子:

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

但是,如果规则是在一个htaccess文件,它是/ABC/文件夹,那么他们需要看起来像这样:

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

我认为你需要一个斜杠的模式'^/ABC的前/(.*)$'并删除斜线查询字符串'... $ 1'? –

+0

@OlafDietsche如果规则在服务器或vhost配置中,则只需在模式前面使用斜线。在发送到htaccess文件中的规则之前,斜杠始终从URI中剥离。 –

+0

谢谢您的解释。我不知道这一点。 –

相关问题