首页 > 解决方案 > 如何使用 .htaccess 将 URL 重定向到新 URL?

问题描述

我想使用 .htaccess 重定向页面。我正在使用代码 igntiter 当用户在地址栏中键入此 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 知之甚少。非常感谢任何帮助,在此先感谢。

编辑:

这是我当前放在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.htaccesscodeignitermod-rewriteurl-rewriting

解决方案


在里面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]

推荐阅读