【问题标题】:CodeIgniter : How to remove 'folder name' in CodeIgniter URLCodeIgniter:如何删除 CodeIgniter URL 中的“文件夹名称”
【发布时间】:2015-05-13 14:38:29
【问题描述】:

所以我有类似的网址:http://localhost/folder_name/home

我想从 URL 中删除/删除 'folder_name',因此我的 URL 变为 http://localhost/home

我已经尝试过这段代码:

RewriteEngine On
RewriteBase /

RewriteRule ^((?!folder_name/).*)$ folder_name/$1 [L,NC,R]

这段代码让我可以访问 http://localhost/home 中的 url,但每次我在浏览器中“按 ENTER”后都会访问该 URL。 URL 将再次变为http://localhost/folder_name/home

是否可以“永久删除”文件夹名称?

谢谢:)

【问题讨论】:

  • 为什么不更改您的虚拟主机设置以将您的域直接指向您的文件夹名称?

标签: php codeigniter url


【解决方案1】:

也许您的网络浏览器仍会记住文件夹名称,然后当您按 Enter 时,它会自动完成旧 URL。

我认为您应该尝试从您的网络浏览器中删除 cookie,然后再试一次。祝你好运!

【讨论】:

  • 我已经清除了我的历史记录和cookies,但是每次我在网络浏览器中启动URL时,都会出现folder_name,尽管我可以在没有folder_name的情况下访问它
【解决方案2】:

尝试使用更灵活的虚拟主机,您甚至可以设置自己的网址,例如myapp.dev

参考此信息:

Windows:

http://en.kioskea.net/faq/8485-configuring-apache-and-windows-to-create-a-virtual-host

在 Linux 中,这取决于您的发行版。

【讨论】:

    【解决方案3】:

    给定:

    http://localhost/folder_name/home

    A.如果您使用的是 XAMPP...
    1) 在您的htdocs 目录中,将folder_name所有内容转移到您的htdocs 目录之外。
    --> 内容包括:application folderassets folder

    2) 删除文件夹folder_name

    B.如果您使用的是 LAMP...
    1) 在您的/var/www/html/ 目录中,将folder_name全部内容转移到您的/var/www/html/ 目录之外。
    --> 内容包括:application folderassets folder

    2) 删除文件夹folder_name

    A 和 B
    3) 在你的 application/config/config.php 文件中...

    $config['base_url'] = 'http://localhost/';
    

    仅限 B
    4) 做:sudo service apache2 restart

    注意:
    这就是我的htdocs/.htaccess 用于A/var/www/html/.htaccess(隐藏文件)用于B...

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    希望这会有所帮助!和平!

    【讨论】:

      【解决方案4】:

      更新您的 .htaccess

      RewriteEngine on
      RewriteBase /home/
      RewriteCond %{REQUEST_URI} ^system.*
      RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
      RewriteRule ^(.*)$ /index.php/$1 [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?/$1 [L]
      

      【讨论】:

        猜你喜欢
        • 2023-04-10
        • 2019-07-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-28
        相关资源
        最近更新 更多