【问题标题】:Remove Main Folder Name from URL in Codeigniter via htacess通过 htaccess 从 Codeigniter 中的 URL 中删除主文件夹名称
【发布时间】:2020-01-07 11:58:55
【问题描述】:

我在文件夹中安装了 Codeigniter,网站正在从该文件夹运行。

安装文件夹是2019

例如: domainame/2019/

详情页网址为: domainname/2019/content/postname

但我想要的 URL 结构就像只需要隐藏 URL 的文件夹名称

帖子应该在那之后打开

详情页网址为: domainname/content/postname

它不应该影响主文件夹

请给我任何解决方案

【问题讨论】:

  • 您目前是在本地还是服务器上工作?
  • 我在 linux 服务器上在线工作
  • 查看答案,如果对您有帮助,请点赞。
  • 请阅读我的评论
  • 项目名不能隐藏,可以通过路由改变控制器和方法来减少url。

标签: php xcode codeigniter .htaccess


【解决方案1】:

您可以使用 URLREWRITE 或 Mod_Rewrite 来执行此操作(假设您使用 URL 参数)。

例如使用模式 ^([^/]+)/([^/]+)/?$ 和子 URL 2019/index.php?{R:1}={R:2} 会将domainname/2019/index.php?content=postname 转换为domainname/content/postname

有关如何通过 .htaccess 在 Linux/Apache 上执行此操作的更多详细信息,请参阅 https://httpd.apache.org/docs/2.4/rewrite/remapping.html

【讨论】:

  • 我用了这个 RewriteRule ^([^/]+)/([^/]+)/?$ 2019/$1/$2 [L,NC,QSA]
【解决方案2】:
RewriteEngine on
RewriteBase /domainame/2019

RewriteRule ^$ /domainame/2019/index\.php [L]
RewriteCond $1 !^(index\.php|assets|repository|favicon\.gif)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond $1 !^(images.*.(bmp|jpg|jpeg|gif|png|doc|docx|xls|xlsx|ppt|pptx|pdf|rtf|txt|zip|rar|odt))
RewriteCond $1 !^(images.*.(BMP|JPG|JPEG|GIF|PNG|DOC|DOCX|XLS|XLSX|PPT|PPTX|PDF|RTF|TXT|ZIP|RAR|ODT))

RewriteCond $1 !^(images.*.(WEBM|AAC|M4A|F4A|MP3|OGG|OGA|OGV|FLV|MP4|M4V|F4V|MOV))
RewriteCond $1 !^(images.*.(webm|aac|m4a|f4a|mp3|ogg|oga|ogv|flv|mp4|m4v|f4v|mov))

RewriteRule ^(.*)$ /domainame/2019/index.php?/$1 [L]

假设 域名 是一个文件夹

【讨论】:

    猜你喜欢
    • 2019-07-18
    • 2023-04-10
    • 2016-04-13
    • 1970-01-01
    • 1970-01-01
    • 2013-09-29
    • 2014-04-22
    • 1970-01-01
    相关资源
    最近更新 更多