的.htaccess规则作出的网址也是这样吗?页= 1的样子/页/ 1 codeigniter [英] Htaccess rule to make urls like this ?page=1 look like /page/1 in Codeigniter
问题描述
这是怎么我的网址目前看:
http://mysite.com/?page=1
我怎样才能使这项工作?
http://mysite.com/page/1
有一个<一个href="http://stackoverflow.com/questions/3167741/easiest-way-to-make-$p$ptty-urls-e-g-mysite-page1-rather-than-mysitepage-page1">post对计算器,询问了同样的问题。但接受的解决方案是不是为我工作。因为我用codeigniter和我的网页出现了404也许是因为由于CI网站的URL模式是:
域/控制器/法
该系统是假设我要求一个称为网页控制器,当然这两者不存在所谓的1的方法。或者maybye这是因为,在我的htaccess的文件中的其他code有冲突(这是我从CI维基下载,它摆脱了index.php文件,并做了一些安全的东西)。这里是我的整个htaccess文件:
&LT; IfModule mod_rewrite.c&GT;
RewriteEngine叙述上
的RewriteBase /
#Removes用户访问到系统文件夹。此外,这将允许您创建一个System.php控制器,系统可以更换,如果您已重命名系统文件夹。
的RewriteCond%{REQUEST_URI} ^系统。*
重写规则^(。*)$ /index.php?/$1 [L]
#当你的应用程序文件夹没有在系统文件夹中。这段代码prevents用户访问应用程序文件夹中。重命名申请到你的应用程序文件夹名称。
的RewriteCond%{REQUEST_URI} ^应用。*
重写规则^(。*)$ /index.php?/$1 [L]
#Checks,查看是否用户正在试图访问一个有效的文件,诸如图像或CSS文件,如果这是不正确它发送到index.php请求
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$的index.php?/ $ 1 [L]
#pretty的网址分页链接
重写规则(。*)的index.php?页= $ 1
&LT; / IfModule&GT;
非缩进位,我从其他得到了解决方案,因此怀疑是不是为我工作。
这个CI分页问题的任何解决方案?
更新
好了,看了一些文档,现在我有这个工作:
http://mysite.com/home/index/2
什么是htaccess的规则,把它转换成:
http://mysite.com/page/2
您应该使这种配置在 /application/config/routes.php
(并让的.htaccess
只是隐藏在index.php,你已经这样做)。
$航线[页面/(:任何)] ='家/索引/ $ 1';
或者更好,就像@zaherg想起(确保只有数字可以通过匹配):
$航线[页面/(:NUM)] ='家/索引/ $ 1';
这样,所有的请求 http://mysite.com/page/2
将在内部视为的http:// mysite的。 COM /家庭/索引/ 2
等等。
我建议你看看 codeIgniter用户指南 - URI路由和 codeIgniter用户指南 - 教程 - 介绍
祝你好运。
This is how my urls currently look:
http://mysite.com/?page=1
How can I make this work?:
http://mysite.com/page/1
There is a post on StackOverflow that asks the same question. But the accepted solution isn't working for me. Because I am using Codeigniter and my page results in a 404 perhaps because since the url pattern of a CI site is:
domain/controller/method
The system is assuming that I am requesting a controller called "page" and a method called "1" both of which of course doesn't exist. Or maybye it's due to a conflict with the other code in my htaccess file (which I downloaded from the CI wiki, it gets rid of index.php and does a few security things). Here is my entire htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users. Additionally this will allow you to create a System.php controller, 'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder. This snippet prevents user access to the application folder. Rename 'application' to your applications folder name.
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]
#Pretty urls for pagination links
RewriteRule (.*) index.php?page=$1
</IfModule>
The non indented bit is the solution I got from that other SO question that isn't working for me.
Any solutions to this CI pagination issue?
UPDATE
Ok, read some of the docs and now I have this working:
http://mysite.com/home/index/2
What would be the htaccess rule to turn that into?:
http://mysite.com/page/2
You should make this configuration at /application/config/routes.php
(and let the .htaccess
just for hide the index.php as you are already doing).
$route['page/(:any)'] = 'home/index/$1';
Or better, like @zaherg remembered (ensures that only numbers could by matched):
$route['page/(:num)'] = 'home/index/$1';
This way all the requests to http://mysite.com/page/2
will be treated internally as http://mysite.com/home/index/2
and so forth.
I suggest you take a look at CodeIgniter User Guide - URI Routing and CodeIgniter User Guide - Tutorial − Introduction.
Good luck.
这篇关于的.htaccess规则作出的网址也是这样吗?页= 1的样子/页/ 1 codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!