2013-01-12 59 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

謝謝您的解釋。我不知道這一點。 –

相關問題