大网数据广告活动
网站运营与故障问答

.htaccess redirect without changing url in users' address bar

· 52CE 我爱测

My website redirects to /temp when visiting the root, I'd like it to appear as the root, without the /temp in the URL address bar. I have a simple .htaccess: Options +FollowSymlinks RewriteEngine On RewriteBase / RewriteRule ^$ /…

问题原文

原帖链接 · Wen Shenk · CC BY-SA 3.0

My website redirects to /temp when visiting the root, I'd like it to appear as the root, without the /temp in the URL address bar.

I have a simple .htaccess:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^$ /temp [L]

How do I make the address bar show www.example.com instead of www.example.com/temp?

Also, When I see the network panel, I notice the status code is 301, so is this equivalent to a redirect 301?

已采纳解答

原帖链接 · MrWhite · CC BY-SA 3.0

RewriteRule ^$ /temp [L]

If you have a physical directory temp in the root of your filesystem... and since you have omitted the slash from the end of the RewriteRule substitution then mod_dir will attempt to "fix" the request by appending a slash. It does this by issueing a 301 redirect. (You are then presumably relying on the DirectoryIndex to serve the appropriate file from that directory.)

You can resolve this by appending a slash to the end of the substitution, so mod_dir won't try and do this by issuing a redirect. For example:

RewriteRule ^$ /temp/ [L]

I notice the status code is 301, so is this equivalent to a redirect 301

Yes, that is a 301 (permanent) redirect.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2016-07-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。