簡體   English   中英

如何使用htaccess在codeigniter中重寫URL?

[英]How to rewrite URL in codeigniter with htaccess?

我該如何從重寫URL

http://website.com/index.php/content/index/3

http://website.com/content/3

.htaccess文件中?

我已經試過了:

RewriteRule ^(.*)/(.*)$ index.php/$1/index/$2 [L]

但這沒有用。

如果尚未創建其他.htaccess文件,請在項目根目錄中創建.htaccess文件。 將以下代碼粘貼到其中。

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /projectname
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>

使用以下模式:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^([\w-]+)/([\w-]+)$ index.php/$1/index/$2 [L]
</IfModule>

嘗試關注以下內容:

<IfModule mod_rewrite.c>

 Options +FollowSymLinks
 RewriteBase /
 RewriteEngine On
 RewriteCond %{HTTP_HOST} !^www\.
 RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
 #Send request via index.php
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.php?/$1 [L]

</IfModule>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM