我做了一个单页设计,想将somesite.com/contact路由到somesite.com/index.php#contact。我正在使用href id和div id。但是我所做的任何一条路线似乎都没有用。
的示例:
$ route ['contact'] =“pagescontroller / index #contact”;
$ route ['contact'] =“base_url('#contact')”;
我怎么能做这个工作?
提前致谢!
答案 0 :(得分:0)
您需要使用#
,以便浏览器知道您将转到页面的一部分。如果您确实要删除它,可以将其用作控制器方法的参数,用于显示页面并使用javascript来显示页面上的特定ID。
我不这样做,因为每次点击链接都会重新加载页面。 (除非您使用javascript来抑制它并转到相关ID。)
然而,您可以在.htaccess中使用mod_rewrite从您的网址中删除index.php。所以你的网址看起来像http://example.com/#about
codeigniter的.htaccess文件是这样的:
<IfModule mod_rewrite.c>
RewriteEngine On
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'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
#Submitted by: Fabdrol
#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]
</IfModule>
<IfModule !mod_rewrite.c>
# 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
</IfModule>