简体   繁体   English

TYPO3插件的其他URL重写

[英]TYPO3 additional url rewrite for a plugin

RealUrl is a great thing, but it doesnt solve all url problems. RealUrl是一件很了不起的事情,但是它不能解决所有url问题。 Many times I need to shorten the plugin's url. 很多时候,我需要缩短插件的网址。 Or I have specific situation for shortening the urls... 或者我有具体情况来缩短网址...

I'm searching a solution to rewrite the url and let the RealUrl to handle it after. 我正在寻找重写URL的解决方案,然后让RealUrl处理它。 This way I could always additionally append all kinds of rewritings on clients request. 这样,我总是可以根据客户的要求附加各种重写。

For example I would like to shorten: http://yyy.com/zimmer-details/rooms/doppelzimmer/ to http://yyy.com/room-test/doppelzimmer/ 例如,我想缩短一下:http: //yyy.com/zimmer-details/rooms/doppelzimmer/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是文档,rooms是扩展名,doppelzimmer是对象的标题)

In this case I would like to use: 在这种情况下,我想使用:

RewriteRule ^(.*)roomtest(.*)$ $1/zimmer-details/rooms$2 [NC,L]

But sadly, this doesn't work... 但可悲的是,这行不通...

If I add R=301 (so the browser will do the redirection) it will work: 如果我添加R = 301(以便浏览器进行重定向),它将起作用:

RewriteRule ^(.*)roomtest(.*)$ $1/zimmer-details/rooms$2 [NC,L,R=301]

And I would really like to do the redirection internaly.. 我真的很想内部重定向。

I'm not that good at .htaccess, so probably I'm missing something. 我不太擅长.htaccess,所以可能我缺少了一些东西。 It could be also possible that the TYPO3 is making me problems. TYPO3也有可能给我带来麻烦。

Any solution, tips, leds on this one? 任何解决方案,提示,led对此吗?

This is the full .htaccess: 这是完整的.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 ...

For avoiding the current page in speaking path, RealUrl has a configuration set called fixedPostVars , it's used tha same way as common postVars except that instead of the param name you should use the uid of the page on which plugin is placed, like: 为了避免当前页面处于发言路径中,RealUrl具有一个名为fixedPostVars的配置集,它的用法与常见的postVars相同,只是您应该使用放置插件的页面的uid代替param名称,例如:

35 => array(
  array(
    'GETvar' => 'tx_myext_pi1[no_comments]',
    'valueMap' => array(
      'no-comments' => 1
    ),
    'noMatch' => 'bypass',
  )
),

See great tutorial wroten by RU author - Dmitry Dulepov ( fixedPostVars are described in first part): 请参阅由RU作者撰写的精彩教程-Dmitry Dulepov(第一部分介绍了fixedPostVars ):

Keep in mind, that manipulating the RU urls manually within the userfunc can lead (occasionally) to invalid URL handling. 请记住,在userfunc中手动操作RU url可能(偶尔)导致无效的URL处理。

IMO you don't need to do that in .htaccess IMO,您不需要在.htaccess中执行此操作

For example I would like to shorten: http://yyy.com/zimmer-details/rooms/doppelzimmer/ to http://yyy.com/room-test/doppelzimmer/ 例如,我想缩短一下:http: //yyy.com/zimmer-details/rooms/doppelzimmer/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是文档,rooms是扩展名,doppelzimmer是对象的标题)

If zimmer-details is a page in BE (this is how I understand document ) you can ignore it in URL (RealURL adds checkbox in page settings for that) 如果zimmer-details是BE中的页面(这是我对document理解),则可以在URL中忽略它(RealURL在页面设置中为此添加了复选框)

rooms can be ignore in realurl_conf.php , if I remember you need to set is as bypass. 如果我记得您需要将设置为bypass,可以在realurl_conf.php中忽略rooms

When you will set both things your URL will be as short as you want 设置完所有内容后,您的URL将尽可能短

Thank to the Fixus I was on a right track again... Forget about the .htaccess! 感谢Fixus,我再次走上了正确的路...忘记.htaccess了! RealUrl can do it all! RealUrl可以完成所有工作!

Answer to my question is to use RealUrl hooks: 我的问题的答案是使用RealUrl挂钩:

For my example: 对于我的例子:

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']);
}

And include the hooks in the RealUrl: 并在RealUrl中包含钩子:

$TYPO3_CONF_VARS['EXTCONF']['realurl'] = array(
    'encodeSpURL_postProc' => array('user_encodeSpURL_postProc'),
    'decodeSpURL_preProc' => array('user_decodeSpURL_preProc')
);

And the magic happend! 魔术发生了! I guess with this simple replace hook I can do all kind of wonderful things. 我想用这个简单的替换钩子我可以做各种很棒的事情。 Also, you could combine them with the RegEx if needed... 此外,如果需要,您可以将它们与RegEx结合使用...

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

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