【问题标题】:How to redirect URL into a new URL using .htaccess?如何使用 .htaccess 将 URL 重定向到新 URL?
【发布时间】:2021-05-18 23:27:31
【问题描述】:

我想使用 .htaccess 重定向页面。我正在使用代码点火器 当用户在地址栏中输入此 URL 时:

form.bixy.com/salesapp

然后他们按下回车键,URL 应该变成:

form.bixy.com/salesapp/administrator/addusr

我在salesapp 文件夹中有这个.htaccess

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteCond $1 !^(index\.php|images|stylesheets|system/application/sources/) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?/  

</IfModule>

如果删除RewriteRule ^(.*)$ index.php?/ 行,我得到The requested URL was not found on this server.

我对 .htaccess 知之甚少。非常感谢任何帮助,在此先感谢。

编辑:

这是我当前放置在 inside salesapp 文件夹中的 .htaccess:

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteCond $1 !^(index\.php|images|stylesheets|system/application/sources/)

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

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

RewriteRule ^/? /salesapp/administrator/addusr[NC,R=301,L]

</IfModule>

它仍然给我错误,但 URL 应该可以工作

The page isn’t redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

【问题讨论】:

    标签: apache .htaccess codeigniter mod-rewrite url-rewriting


    【解决方案1】:

    salesapp 中你可以试试这个.htaccess:

    RewriteEngine on
    RewriteBase /salesapp/
    
    RewriteRule ^(?:administrator)?/?$ administrator/addusr [R=301,L,NC]
    
    RewriteCond $1 !^(index\.php|images|stylesheets|system/application/sources/) [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/?$ index.php  [L]
    

    【讨论】:

    • 非常感谢它运行良好。但是,一件小事,如何做到这一点,当用户输入form.bixy.com/salesapp/administrator/ 它也重定向到form.bixy.com/salesapp/administrator/addusr
    • 当我输入form.bixy.com/salesapp 时它不起作用。它应该适用于form.bixy.com/salesappform.bixy.com/salesapp/administrator,它们将被重定向到form.bixy.com/salesapp/administrator/addusr
    • 啊,我有一个错字。现在试试吧,在非捕获组后错过了?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-14
    • 2017-09-25
    • 2019-10-15
    • 2022-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多