apache - 如何使用 .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.
解决方案
在里面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]
推荐阅读
- java - 如何在 android 中使用来自 apache/poi/ss/formula/functions/Mirr.html 的 Mirr() 函数?
- php - 运行安装在我的机器上的 phpMyadmin MySql 和 MySQL root 的可预见问题
- python - 例如,如何获得夜间 = 1 的列的平均值/平均值
- python - 如何使用 Python 获取属性 XPATH 列表?
- python - 当我尝试附加值时出现 NameError
- c++ - c++中的动态分配问题,仅适用于第一次迭代
- node.js - 在 mongo db 集合中给出未定义的值
- rubygems - 如何选择实时推送通知 API
- visual-c++ - 为什么在我的静态库的 DUMPBIN.exe 输出中,`malloc` 和 `free` 被列为 `External` 和 `UNDEF`?
- wordpress - 删除特定角色的 wp 管理栏节点 - $wp_admin_bar->remove_node( 'string' );