TYPO3 追加 url 重写一个插件
TYPO3 additional url rewrite for a plugin
RealUrl 是个好东西,但它并不能解决所有 url 问题。很多时候我需要缩短插件的url。或者我有缩短 urls...
的具体情况
我正在寻找重写 url 的解决方案,然后让 RealUrl 处理它。这样我就可以随时根据客户的要求附加各种重写。
例如我想缩短:
http://yyy.com/zimmer-details/rooms/doppelzimmer/
到
http://yyy.com/room-test/doppelzimmer/
(其中:zimmer-details 是文档,rooms 是扩展名,doppelzimmer 是 object 中的标题)
在这种情况下,我想使用:
RewriteRule ^(.*)roomtest(.*)$ /zimmer-details/rooms [NC,L]
但遗憾的是,这不起作用...
如果我添加 R=301(这样浏览器就会进行重定向),它将起作用:
RewriteRule ^(.*)roomtest(.*)$ /zimmer-details/rooms [NC,L,R=301]
我真的很想在内部进行重定向..
我不太擅长 .htaccess,所以我可能遗漏了什么。也可能是 TYPO3 给我带来了麻烦。
关于这个的任何解决方案、技巧、指示灯?
这是完整的 .htaccess:
### Begin: Settings for mod_rewrite ###
# You need rewriting, if you use a URL-Rewriting extension (RealURL, CoolUri, SimulateStatic).
<IfModule mod_rewrite.c>
# Enable URL rewriting
RewriteEngine On
# Change this path, if your TYPO3 installation is located in a subdirectory of the website root.
RewriteBase /
# activate minification of css and js
RewriteRule ^(.*\.(css|js).*)$ min/index.php?f=&debug=0 [L,NC]
# !!! MY REWRITE !!!
RewriteRule ^(.*)roomtest(.*)$ /zimmer-details/rooms [NC]
# Rule for versioned static files, configured through:
# - $TYPO3_CONF_VARS['BE']['versionNumberInFilename']
# - $TYPO3_CONF_VARS['FE']['versionNumberInFilename']
# IMPORTANT: This rule has to be the very first RewriteCond in order to work!
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ . [L]
# Stop rewrite processing, if we are in the typo3/ directory.
# For httpd.conf, use this line instead of the next one:
# RewriteRule ^/TYPO3root/(typo3/|t3lib/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]
RewriteRule ^(typo3/|t3lib/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]
# Redirect http://example.com/typo3 to http://example.com/typo3/index_re.php and stop the rewrite processing.
# For httpd.conf, use this line instead of the next one:
# RewriteRule ^/TYPO3root/typo3$ /TYPO3root/typo3/index.php [L]
RewriteRule ^typo3$ typo3/index_re.php [L]
# Don't pull *.xml, *.css etc. from the cache
RewriteCond %{REQUEST_FILENAME} !^.*\.xml$
RewriteCond %{REQUEST_FILENAME} !^.*\.css$
# Check for Ctrl Shift reload
RewriteCond %{HTTP:Pragma} !no-cache
RewriteCond %{HTTP:Cache-Control} !no-cache
# NO backend user is logged in. Please note that the be_typo_user expires at the
# end of the browser session. So, although you have already logged out of the
# backend, you will still have to either restart your browser or remove the
# cookie manually for this rule to work.
RewriteCond %{HTTP_COOKIE} !be_typo_user [NC]
# NO frontend user is logged in. Logged in frontend users may see different
# information than anonymous users. But the anonymous version is cached. So
# don't show the anonymous version to logged in frontend users.
RewriteCond %{HTTP_COOKIE} !nc_staticfilecache [NC]
# We only redirect GET requests
RewriteCond %{REQUEST_METHOD} GET
# We only redirect URI's without query strings
RewriteCond %{QUERY_STRING} ^$
</IfModule>
### End: Settings for mod_rewrite ###
+ some other caching things ...
IMO 你不需要在 .htaccess 中这样做
For example I would like to shorten: http://yyy.com/zimmer-details/rooms/doppelzimmer/ to http://yyy.com/room-test/doppelzimmer/
(where: zimmer-details is a document, rooms is an extension and doppelzimmer is a title from a object)
如果zimmer-details
是BE中的一个页面(我是这样理解的document
)你可以在URL中忽略它(RealURL在页面设置中添加了复选框为此)
rooms
在realurl_conf.php
中可以忽略,如果我记得你需要设置为绕过
当您设置这两项时,您的 URL 将尽可能短
多亏了 Fixus,我又走上了正轨...忘掉 .htaccess!
RealUrl 可以做到这一切!
我的问题的答案是使用 RealUrl 挂钩:
以我为例:
function user_encodeSpURL_postProc(&$params, &$ref) {
$params['URL'] = str_replace('zimmer-details/rooms/', 'room/', $params['URL']);
}
function user_decodeSpURL_preProc(&$params, &$ref) {
$params['URL'] = str_replace('room/', 'zimmer-details/rooms/', $params['URL']);
}
并在 RealUrl 中包含挂钩:
$TYPO3_CONF_VARS['EXTCONF']['realurl'] = array(
'encodeSpURL_postProc' => array('user_encodeSpURL_postProc'),
'decodeSpURL_preProc' => array('user_decodeSpURL_preProc')
);
奇迹发生了!
我想用这个简单的替换钩子我可以做各种美妙的事情。
此外,如果需要,您可以将它们与 RegEx 结合使用...
为了避免在说话路径中出现当前页面,RealUrl 有一个名为 fixedPostVars
的配置集,它的使用方式与常见的 postVars
相同,只是您应该使用 uid 而不是参数名称放置插件的页面,例如:
35 => array(
array(
'GETvar' => 'tx_myext_pi1[no_comments]',
'valueMap' => array(
'no-comments' => 1
),
'noMatch' => 'bypass',
)
),
请参阅 RU 作者 Dmitry Dulepov 撰写的精彩教程(fixedPostVars
在第一部分中进行了描述):
请记住,在 userfunc 中手动操作 RU url 可能会(偶尔)导致无效的 URL 处理。
RealUrl 是个好东西,但它并不能解决所有 url 问题。很多时候我需要缩短插件的url。或者我有缩短 urls...
的具体情况我正在寻找重写 url 的解决方案,然后让 RealUrl 处理它。这样我就可以随时根据客户的要求附加各种重写。
例如我想缩短: http://yyy.com/zimmer-details/rooms/doppelzimmer/ 到 http://yyy.com/room-test/doppelzimmer/
(其中:zimmer-details 是文档,rooms 是扩展名,doppelzimmer 是 object 中的标题)
在这种情况下,我想使用:
RewriteRule ^(.*)roomtest(.*)$ /zimmer-details/rooms [NC,L]
但遗憾的是,这不起作用...
如果我添加 R=301(这样浏览器就会进行重定向),它将起作用:
RewriteRule ^(.*)roomtest(.*)$ /zimmer-details/rooms [NC,L,R=301]
我真的很想在内部进行重定向..
我不太擅长 .htaccess,所以我可能遗漏了什么。也可能是 TYPO3 给我带来了麻烦。
关于这个的任何解决方案、技巧、指示灯?
这是完整的 .htaccess:
### Begin: Settings for mod_rewrite ###
# You need rewriting, if you use a URL-Rewriting extension (RealURL, CoolUri, SimulateStatic).
<IfModule mod_rewrite.c>
# Enable URL rewriting
RewriteEngine On
# Change this path, if your TYPO3 installation is located in a subdirectory of the website root.
RewriteBase /
# activate minification of css and js
RewriteRule ^(.*\.(css|js).*)$ min/index.php?f=&debug=0 [L,NC]
# !!! MY REWRITE !!!
RewriteRule ^(.*)roomtest(.*)$ /zimmer-details/rooms [NC]
# Rule for versioned static files, configured through:
# - $TYPO3_CONF_VARS['BE']['versionNumberInFilename']
# - $TYPO3_CONF_VARS['FE']['versionNumberInFilename']
# IMPORTANT: This rule has to be the very first RewriteCond in order to work!
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ . [L]
# Stop rewrite processing, if we are in the typo3/ directory.
# For httpd.conf, use this line instead of the next one:
# RewriteRule ^/TYPO3root/(typo3/|t3lib/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]
RewriteRule ^(typo3/|t3lib/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]
# Redirect http://example.com/typo3 to http://example.com/typo3/index_re.php and stop the rewrite processing.
# For httpd.conf, use this line instead of the next one:
# RewriteRule ^/TYPO3root/typo3$ /TYPO3root/typo3/index.php [L]
RewriteRule ^typo3$ typo3/index_re.php [L]
# Don't pull *.xml, *.css etc. from the cache
RewriteCond %{REQUEST_FILENAME} !^.*\.xml$
RewriteCond %{REQUEST_FILENAME} !^.*\.css$
# Check for Ctrl Shift reload
RewriteCond %{HTTP:Pragma} !no-cache
RewriteCond %{HTTP:Cache-Control} !no-cache
# NO backend user is logged in. Please note that the be_typo_user expires at the
# end of the browser session. So, although you have already logged out of the
# backend, you will still have to either restart your browser or remove the
# cookie manually for this rule to work.
RewriteCond %{HTTP_COOKIE} !be_typo_user [NC]
# NO frontend user is logged in. Logged in frontend users may see different
# information than anonymous users. But the anonymous version is cached. So
# don't show the anonymous version to logged in frontend users.
RewriteCond %{HTTP_COOKIE} !nc_staticfilecache [NC]
# We only redirect GET requests
RewriteCond %{REQUEST_METHOD} GET
# We only redirect URI's without query strings
RewriteCond %{QUERY_STRING} ^$
</IfModule>
### End: Settings for mod_rewrite ###
+ some other caching things ...
IMO 你不需要在 .htaccess 中这样做
For example I would like to shorten: http://yyy.com/zimmer-details/rooms/doppelzimmer/ to http://yyy.com/room-test/doppelzimmer/
(where: zimmer-details is a document, rooms is an extension and doppelzimmer is a title from a object)
如果zimmer-details
是BE中的一个页面(我是这样理解的document
)你可以在URL中忽略它(RealURL在页面设置中添加了复选框为此)
rooms
在realurl_conf.php
中可以忽略,如果我记得你需要设置为绕过
当您设置这两项时,您的 URL 将尽可能短
多亏了 Fixus,我又走上了正轨...忘掉 .htaccess! RealUrl 可以做到这一切!
我的问题的答案是使用 RealUrl 挂钩:
以我为例:
function user_encodeSpURL_postProc(&$params, &$ref) {
$params['URL'] = str_replace('zimmer-details/rooms/', 'room/', $params['URL']);
}
function user_decodeSpURL_preProc(&$params, &$ref) {
$params['URL'] = str_replace('room/', 'zimmer-details/rooms/', $params['URL']);
}
并在 RealUrl 中包含挂钩:
$TYPO3_CONF_VARS['EXTCONF']['realurl'] = array(
'encodeSpURL_postProc' => array('user_encodeSpURL_postProc'),
'decodeSpURL_preProc' => array('user_decodeSpURL_preProc')
);
奇迹发生了! 我想用这个简单的替换钩子我可以做各种美妙的事情。 此外,如果需要,您可以将它们与 RegEx 结合使用...
为了避免在说话路径中出现当前页面,RealUrl 有一个名为 fixedPostVars
的配置集,它的使用方式与常见的 postVars
相同,只是您应该使用 uid 而不是参数名称放置插件的页面,例如:
35 => array(
array(
'GETvar' => 'tx_myext_pi1[no_comments]',
'valueMap' => array(
'no-comments' => 1
),
'noMatch' => 'bypass',
)
),
请参阅 RU 作者 Dmitry Dulepov 撰写的精彩教程(fixedPostVars
在第一部分中进行了描述):
请记住,在 userfunc 中手动操作 RU url 可能会(偶尔)导致无效的 URL 处理。