简体   繁体   English

在TYPO3中使用.htaccess隐藏/重定向到子文件夹

[英]Hidden redirect of / to subfolder using .htaccess in TYPO3

We're setting up a TYPO3 installation, and if the user calls example.com/ we'd like the server to redirect to /typo/index.php?id=106 . 我们正在设置TYPO3安装,如果用户调用example.com/,我们希望服务器重定向到/typo/index.php?id=106

This should happen without a change in the address bar. 无需更改地址栏即可完成此操作。 Every other file access on the server (for example example.com/test.png) should be redirected to example.com/typo/test.png). 服务器上的所有其他文件访问(例如example.com/test.png)都应重定向到example.com/typo/test.png。

This is the .htaccess file in the root directory. 这是根目录中的.htaccess文件。 As I understand, it will redirect everything which doesn't have /typo in the URL to the subfolder and attach the parameters: 据我了解,它将重定向URL中没有/ typo的所有内容到子文件夹并附加参数:

RewriteCond %{REQUEST_URI} !^/typo/
RewriteRule ^(.*)$ typo/$1 [L]

Now, this already seems to work, when I call example.com/index.php?id=106 I'm not getting a 404. Unfortunately TYPO3 seems to have some trouble (or the .htaccess configuration isn't correct), because we get a message saying "No input file specified". 现在,当我调用example.com/index.php?id=106时,这似乎已经可以工作了,但是我没有得到404。不幸的是TYPO3似乎有一些麻烦(或者.htaccess配置不正确),因为我们收到一条消息,提示“未指定输入文件”。

What's also missing is the initial redirect when no path is specified. 当没有指定路径时,还缺少初始重定向。 It should then go to /typo/index.php?id=106. 然后应转到/typo/index.php?id=106。

You may try this in one .htaccess file in root directory: 您可以在根目录的一个.htaccess文件中尝试此操作:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /

# URL with no path
RewriteCond %{REQUEST_URI}  ^/?$        [NC]
RewriteCond %{REQUEST_URI}  !index\.php [NC]
RewriteRule .*  /typo/index.php?id=106  [NC,L]

# URL with path    
RewriteCond %{REQUEST_URI}  !^/typo     [NC]
RewriteRule ^(.+)  /typo/$1             [NC,L]

Maps silently: 静默映射:

http://domain.com/ to http://domain.com/

http://domain.com/typo/index.php?id=106

and

http://domain.com/anything

http://domain.com/typo/anything

For permanent redirection, replace [NC,L] with [R=301,NC,L] 对于永久重定向,将[NC,L]替换为[R = 301,NC,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM