重写 codeigniter 站点的 htaccess

发布于 2024-12-09 01:52:25 字数 587 浏览 7 评论 0原文

我想重写 codeigniter url 重写的代码。

我使用了以下代码。

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

RewriteRule ^admin$ administration
RewriteRule ^video/([0-9]+)/(.*)$ videos/details/$1/$1

它对于删除 index.php 效果很好。 但它不适用于网址重写,

我希望 example.com/admin 变为 example.com/administration

example.com/video/123/title< /code> 变为 example.com/videos/details/123/title

提前致谢, w3父亲

I want to rewrite code for codeigniter url rewrite.

I have used following code.

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

RewriteRule ^admin$ administration
RewriteRule ^video/([0-9]+)/(.*)$ videos/details/$1/$1

It is working well for index.php removal.
But it doesn't work for url rewrite

i want example.com/admin becomes example.com/administration

and

example.com/video/123/title becomes example.com/videos/details/123/title

Thanks in advance,
w3father

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

很糊涂小朋友 2024-12-16 01:52:25

您应该使用以下 .htaccess:

<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,
    #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> 

并将您的路由添加到 application/config 文件夹内的 paths.php 中。有关详细信息,请参阅 URI 路由

You should use the following .htaccess:

<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,
    #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> 

And add your routes to the routes.php inside the application/config folder. See URI Routing for more information.

夢归不見 2024-12-16 01:52:25

我相信您所需要做的就是将两条新规则放在现有规则之前。

RewriteEngine On
RewriteBase /whype

RewriteRule ^admin$ administration
RewriteRule ^video/([0-9]+)/(.*)$ videos/details/$1/$2

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

I believe all you need to do is put your two new rules in front of the existing ones.

RewriteEngine On
RewriteBase /whype

RewriteRule ^admin$ administration
RewriteRule ^video/([0-9]+)/(.*)$ videos/details/$1/$2

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文