【发布时间】:2017-07-15 17:57:39
【问题描述】:
我遇到了 mod rewrite 的问题。我也是它的初学者。我正在使用 CodeIgniter 并尝试重写以下内容:
http://url.dev/news/news_selection?item=59
看起来像这样:
http://url.dev/news/news_selection/59/
我遵循了以下教程:https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/(更具体地说,是:“模式和替换”部分)
问题是我将我的 RewriteRule 编写如下,但在转到页面后它仍然没有重写 url(例如http://url.dev/news/news_selection?item=59)
RewriteRule ^news/news_selection/([0-9]+)/?$ news_selection?item=$1 [NC,L]
对我哪里出错有什么建议吗?谢谢。
我不确定路由和控制器是否会影响这个问题,但我添加了它们以供参考。
在我的 codeIgniter 路线中,我有
//_News Folder
$route['news/(:any)'] = 'pages/view2/_news/$1';
1:_news 是文件夹
2:news_selection是php文件
3:页面是控制器
我的控制器对 view2 有以下功能:
public function view2($sub ='', $page='')
{
if ( ! file_exists(APPPATH.'/views/pages/'.$sub.'/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = ucfirst($page); // Capitalize the first letter
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$sub.'/'.$page.'.php', $data);
$this->load->view('templates/footer', $data);
}
我的 .htaccess 的其余部分:
Options -Indexes
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
#When your application folder isn't in the system folder
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
【问题讨论】:
标签: .htaccess codeigniter mod-rewrite