RealUrl是一件伟大的事情,但它并不能解决所有的url问题。很多时候,我需要缩短插件的网址。或者我有缩短网址的特殊情况..。
我正在寻找一个重写url的解决方案,然后让RealUrl来处理它。通过这种方式,我总是可以在客户请求上附加各种重写。
例如,我想缩短:http://yyy.com/zimmer-details/rooms/doppelzimmer/到http://yyy.com/room-test/doppelzimmer/
(其中: zimmer-details是一个文档,房间是一个扩展,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也可能给我带来麻烦。
这个有解决方案,提示,leds吗?
这是完整的.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 ...发布于 2015-03-16 10:43:44
感谢菲克斯我又回到了正确的轨道上..。忘记.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结合起来.
发布于 2015-03-16 11:05:19
为了避免说话路径中的当前页面,RealUrl有一个名为fixedPostVars的配置集,它的使用方式与普通postVars相同,只是您应该使用放置插件的页面的uid,而不是param名称,例如:
35 => array(
array(
'GETvar' => 'tx_myext_pi1[no_comments]',
'valueMap' => array(
'no-comments' => 1
),
'noMatch' => 'bypass',
)
),参见RU作者的伟大教程wroten - Dulepov (fixedPostVars在第一部分中介绍):
请记住,在userfunc中手动操作RU URL可能导致(偶尔)无效的URL处理。
发布于 2015-03-16 10:18:24
海事组织,你不需要在.htaccess里这么做
例如,我想缩短:http://yyy.com/zimmer-details/rooms/doppelzimmer/到http://yyy.com/room-test/doppelzimmer/ (其中: zimmer-details是一个文档,房间是一个扩展,doppelzimmer是一个对象的标题)
如果zimmer-details是BE中的页面(这是我理解document的方式),您可以在URL中忽略它(RealURL在页面设置中添加复选框)
rooms在realurl_conf.php中可以忽略,如果我记得你需要设置为旁路。
当您将两种设置都设置时,您的URL将尽可能短
https://stackoverflow.com/questions/29072028
复制相似问题