您好,我是 CI 的新手,我被困在某個地方。我想要的是我有像這樣的網址domain.com/article?seo=What-Software-Program&id=7在這里,我最后通過 id 獲取文章,并使用 seo 在 url 中使用與 thsse 相關的關鍵字以獲得更好的 SEO現在我想從那個 url 看起來像這樣domain.com/article/What-Software-Program/id/7我想從 url 中刪除?seo=并將其替換為 /我已成功配置我的路由頁面以在沒有 index.php 和主控制器的情況下路由 url這是我的路線頁面$route['default_controller'] = 'main';$route['404_override'] = '';$route['translate_uri_dashes'] = FALSE;$route['(:any)'] = "main/$1";$route['admin'] = 'admin/login';和我的 htaccessRewriteEngine On# remove /index.php/main/ from URLsRewriteCond %{REQUEST_METHOD} !POSTRewriteCond %{THE_REQUEST} \s/+index\.php/main/ [NC]RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]RewriteRule ^index\.php/main(/.*)?$ https://%1$1 [L,NC,NE,R=301]RewriteCond %{HTTPS} off [OR]RewriteCond %{HTTP_HOST} ^www\. [NC]RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ index.php [L] Header set Access-Control-Allow-Origin "*"</IfModule># remove index.phpRewriteCond %{REQUEST_METHOD} !POSTRewriteCond %{THE_REQUEST} /index\.php [NC]RewriteCond %{REQUEST_URI} ^(.*/)index\.php$ [NC]RewriteRule ^ %1 [L,R=301,NE]# To externally redirect /dir/file.php to /dir/fileRewriteCond %{REQUEST_METHOD} !POSTRewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]RewriteRule ^ /%1 [R=301,NE,L]# To internally forward /dir/file to /dir/file.phpRewriteCond %{DOCUMENT_ROOT}/$1.php -fRewriteRule ^(.+?)/?$ $1.php [L]Header set Access-Control-Allow-Origin "*"RewriteEngine onRewriteCond $1 !^(index\.php|resources|robots\.txt)RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ index.php?/$1 [L,QSA]
1 回答

FFIVE
TA貢獻1797條經驗 獲得超6個贊
For this type of url : domain.com/article/What-Software-Program/id/7
請在 routes.php 文件中添加以下路由。
$route['article/(:any)/id/(:num)'] = "controller_name/function_name/$1/$2";
- 1 回答
- 0 關注
- 94 瀏覽
添加回答
舉報
0/150
提交
取消