大网数据广告活动
服务器运维问答

What .htaccess RewriteRule do I need to redirect correctly when no page is specified in the URL?

· 52CE 我爱测

In my directory http://tanguay.info/webtech I have the following .htaccess file: RewriteEngine On RewriteRule ^$ http://127.0.0.1:49900/home [P,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRul…

问题原文

原帖链接 · Edward Tanguay · CC BY-SA 4.0

In my directory

http://tanguay.info/webtech

I have the following .htaccess file:

RewriteEngine On
RewriteRule ^$ http://127.0.0.1:49900/home [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:49900/$1 [P,L]

It routes correctly if I provide a page (a node app with .eps files)

http://tanguay.info/webtech/home

But if I don't provide a page:

http://tanguay.info/webtech

It gives this error:

Error: ENOENT: no such file or directory, open '/home/tanguay2/public_html/n49900_dpndev/systemPages/index.html.var.ejs'

It seems to be going to index.html.var.ejs instead of the http://127.0.0.1:49900/home that I specified, but I don't know where it is getting this index.html.var information.

How do I get it to correctly link to http://tanguay.info:49900 if I provide no page?

已采纳解答

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

index.html.var maybe set as your DirectoryIndex. In which case, mod_dir issues an internal subrequest for this document. (Does this file exist?)

How you match this with mod_rewrite can depend on your Apache version (2.2 vs 2.4). In Apache 2.2 mod_dir executes before mod_rewrite. The order reversed in 2.4.

In Apache 2.4 a RewriteRule pattern of ^$ should be sufficient (since it is processed before mod_dir issues the subrequest). If the directory index document does not exist then this should also work on Apache 2.2. However, to catch both possibilities then check for both...

For example, change your first RewriteRule to read:

RewriteRule ^(index\.html\.var)?$ http://127.0.0.1:49900/home [P,L]

Or, you could disable the DirectoryIndex (if it's not being used) at the top of your .htaccess file:

DirectoryIndex disabled

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

资料来源与适用范围

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

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

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