0

我做了一个单页设计,并希望将 somesite.com/contact 路由到 somesite.com/index.php#contact。我正在使用 href id 和 div id。但我做的所有路线似乎都没有奏效。

例子:

  • $route['contact'] = "pagescontroller/index#contact";

  • $route['contact'] = "base_url('#contact')";

我怎样才能使这项工作?

提前致谢!

4

1 回答 1

0

您将需要使用#以便浏览器知道您将转到页面的一部分。如果你真的想删除它,你可以将它用作你用来显示你的页面的控制器方法的参数,并使用 javascript 去你页面上的那个特定的 id。
我不会这样做,因为每次单击链接时都会重新加载页面。(除非您也使用 javascript 来抑制它并转到相关 ID。)

但是,您可以在 .htaccess 中使用 mod_rewrite 从您的 url 中删除 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> 
于 2012-05-11T16:51:20.253 回答