Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php CodeIgniter URL重写_Php_.htaccess_Codeigniter - Fatal编程技术网

Php CodeIgniter URL重写

Php CodeIgniter URL重写,php,.htaccess,codeigniter,Php,.htaccess,Codeigniter,我试图重写CodeIgniter应用程序的URL,尽管它似乎不起作用。 我有以下几件事要做 $route['pages/(:num)/(:any)'] = "pages/view/$1/$2"; $config['index_page'] = ''; 那么我就有了以下内容。htaccess RewriteEngine on RewriteBase / RewriteRule ^pages/(.*)/(.*)$ /index.php/pages/view/$1/$2 [L] 它只是说找不到页

我试图重写CodeIgniter应用程序的URL,尽管它似乎不起作用。 我有以下几件事要做

$route['pages/(:num)/(:any)'] = "pages/view/$1/$2";
$config['index_page'] = '';
那么我就有了以下内容。htaccess

RewriteEngine on
RewriteBase /

RewriteRule ^pages/(.*)/(.*)$ /index.php/pages/view/$1/$2 [L]
它只是说找不到页面(一个Apache错误,而不是CodeIgniter)。 当我浏览到原始链接时,它会起作用(http://domain.tld/index.php/pages/view/1/welcome)但当浏览到“所需”链接时,情况并非如此(http://domain.tld/pages/1/welcome)


我做错了什么?

可能是您的重写规则中缺少了一个

# Substitute " >>?<< " with "?". It's there to point you to the change.
RewriteRule ^pages/(.*)/(.*)$ /index.php >>?<< /pages/view/$1/$2 [L]
#替换“>>?尝试:

$route[“pages/(.*)/(.*)”]=“pages/view/$1/$2”; //和您的Htaces,删除您当前的规则并 重写规则^(.*)$index.php/$1[L]
我认为你需要有htaccess才能从url中删除index.php,它应该不太管用,它不仅要删除'index.php',还要删除方法的名称;view。你有没有检查过apache日志以了解apache将其改写为什么?此外,你可能需要非贪婪版本的$1匹配ie
^pages/(.*)/(.*)$
我不想听起来太傻,但显然我的服务器还不支持htaccess,我更改了apache vhost,现在它正在进行一些调整。不是这样,Codeigniter使用斜杠格式,加上op声明手动使用重写版本Works可以使用它。谢谢。 $route["pages/(.*)/(.*)"] = "pages/view/$1/$2"; //and your htacess, remove your current rule and RewriteRule ^(.*)$ index.php/$1 [L]