[英]TYPO3 additional url rewrite for a plugin
RealUrl是一件很了不起的事情,但是它不能解決所有url問題。 很多時候,我需要縮短插件的網址。 或者我有具體情況來縮短網址...
我正在尋找重寫URL的解決方案,然后讓RealUrl處理它。 這樣,我總是可以根據客戶的要求附加各種重寫。
例如,我想縮短一下:http: //yyy.com/zimmer-details/rooms/doppelzimmer/到http://yyy.com/room-test/doppelzimmer/
(其中:zimmer-details是文檔,rooms是擴展名,doppelzimmer是對象的標題)
在這種情況下,我想使用:
RewriteRule ^(.*)roomtest(.*)$ $1/zimmer-details/rooms$2 [NC,L]
但可悲的是,這行不通...
如果我添加R = 301(以便瀏覽器進行重定向),它將起作用:
RewriteRule ^(.*)roomtest(.*)$ $1/zimmer-details/rooms$2 [NC,L,R=301]
我真的很想內部重定向。
我不太擅長.htaccess,所以可能我缺少了一些東西。 TYPO3也有可能給我帶來麻煩。
任何解決方案,提示,led對此嗎?
這是完整的.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=$1&debug=0 [L,NC]
# !!! MY REWRITE !!!
RewriteRule ^(.*)roomtest(.*)$ $1/zimmer-details/rooms$2 [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)$ $1.$3 [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 ...
為了避免當前頁面處於發言路徑中,RealUrl具有一個名為fixedPostVars
的配置集,它的用法與常見的postVars
相同,只是您應該使用放置插件的頁面的uid代替param名稱,例如:
35 => array(
array(
'GETvar' => 'tx_myext_pi1[no_comments]',
'valueMap' => array(
'no-comments' => 1
),
'noMatch' => 'bypass',
)
),
請參閱由RU作者撰寫的精彩教程-Dmitry Dulepov(第一部分介紹了fixedPostVars
):
請記住,在userfunc中手動操作RU url可能(偶爾)導致無效的URL處理。
IMO,您不需要在.htaccess中執行此操作
例如,我想縮短一下:http: //yyy.com/zimmer-details/rooms/doppelzimmer/到http://yyy.com/room-test/doppelzimmer/
(其中:zimmer-details是文檔,rooms是擴展名,doppelzimmer是對象的標題)
如果zimmer-details
是BE中的頁面(這是我對document
理解),則可以在URL中忽略它(RealURL在頁面設置中為此添加了復選框)
如果我記得您需要將設置為bypass,可以在realurl_conf.php
中忽略rooms
。
設置完所有內容后,您的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結合使用...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.