.htaccess - htaccess 重定向而不改变 url

标签 .htaccess

我有几个类似的 url

http://www.mydomain.com/statecode1-folder1

我想将它重定向到/folder1/页面,但我想在浏览器地址栏中显示上面的原始 url。

请注意,我没有文件夹 statecode1-folder1 和 statecode2-folder1

目前我使用下面的 .htaccess 重定向但是它改变了地址栏

#Options +FollowSymlinks 
RewriteEngine On
RewriteBase   /
RewriteCond  %{REQUEST_URI}   ^/ statecode1-folder1 $  
RewriteRule   ^(.+)  / folder1 [L]
RewriteCond  %{REQUEST_URI}   ^/ statecode2-folder1 $  
RewriteRule   ^(.+)  / folder1 [L]

最佳答案

斜杠后不应该有空格!结尾 $ 也许是问题所在?通常,本地重定向应该有效。尝试这样的事情:

RewriteEngine On
RewriteBase   /
RewriteCond  %{REQUEST_URI}   ^/statecode1-folder1
RewriteRule   ^.*  /folder1 [L]
RewriteCond  %{REQUEST_URI}   ^/statecode2-folder1
RewriteRule   ^.*  /folder1 [L]

关于.htaccess - htaccess 重定向而不改变 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4744336/

相关文章:

.htaccess - 如何使用 htaccess 将域重定向到子域?

在 .htaccess 中使用 FilesMatch 和 Headers 所需的 Apache 模块

php - 在 codeigniter 中删除 index.php(在本地工作正常但在生产环境中不工作)

php - Slim .htaccess 静态文件问题

.htaccess - 将 htaccess 转换为 nginx

php - 在使用重定向进行迁移时保持旧 URL 有效

.htaccess - htaccess 重写多个文件夹

apache - htaccess 不适用于本地主机

php - .htaccess 与 ^(.*)$ index.php/$1 给出 "No input file specified"

windows - 如何手动创建扩展名为 . Windows 中的(点)前缀?例如,.htaccess