How to make short links in news?
Hi!!
I'm using a news system and all my news have url like this:
[siteurl]/news-reader/items/title-of-news.html
And I want to make it shorties, without /items/ or beter - without /news-reader/items/
so I want do this
link "news" in main menu r_e_d_i_r_e_c_t you to the latest news.
all news have url like [site_url]/news-title.html
I found where "/items/" add to url and changed it to "/" , but I can't figure out how to make this work, because typolight can't work without "items" param in url,
I tried to change httaccess file to add url with "items" to inner part ... but I not good in httaccess and that don't work.
Could someone help me ?
Re: How to make short links in news?
The whole point of the news reader is to have only 1 page that can read many stories, but in order to do that, it MUST have a parameter. So, your situation will never work, because the News Reader is always expecting a parameter.
Code:
news-reader-page/items/news-title-alias.html
is actually
Code:
news-reader-page.html?items=news-title-alias
without the items GET parameter, the module cannot determine which item its supposed to display. Also since there is no check to determine if your News URL alias (the news-title-alias.html) is perhaps a copy of the page-title-alias.html or even a event-title-alias.html, you could run into serious problems here.
The best way to "avoid" what you're doing is to use the news system as an article indexer, and point each news story directly to a page where you've written the news story.
Re: How to make short links in news?
Hi thyon!
But I think on .htaccess I can made that by mod_rewrite before this line?
RewriteRule .*\.html$ index.php [L]
1) I delete automaticaly adding "/items/" in php.
and get urls like
news-reader/my_news.html
2) write rule in htaccess:
RewriteRule ^news-reader/(.*).html$ news-reader/items/$1.html [qsa]
yes?
P.s. I can't test this now.... :(
Re: How to make short links in news?
Hi thyon!
Your post about how actually looks url for news is really useful for me.
I already made new “hardcode” for news in my typolight site.
Now I have this logic
1) if you click to [site_url]/news.html you would be redirect to latest news. And url will be like this:
[site_url]/news/latest-news-alias.html
2) All news have url like this: [site_url]/news/news-alias.html and it shown perfectly.
For make this work you should make some things.
!!! in my site “news” named “nyheter”!!!!
1. Change line# 310 in \system\modules\news\ModuleNews.php
From:
Code:
$strUrl = ampersand($this->generateFrontendUrl($objPage->fetchAssoc(), '/items/' . ((!$GLOBALS['TL_CONFIG']['disableAlias'] && strlen($objArticle->alias)) ? $objArticle->alias : $objArticle->id)));
To:
Code:
$strUrl = ampersand($this->generateFrontendUrl($objPage->fetchAssoc(), '/' . ((!$GLOBALS['TL_CONFIG']['disableAlias'] && strlen($objArticle->alias)) ? $objArticle->alias : $objArticle->id)));
I mean change ‘/items/’ to ‘/’
2. Go to .htaccess and write this:
Code:
RewriteCond %{REQUEST_URI} nyheter/(.*)\.html$
RewriteRule ^nyheter/(.*)\.html$ nyheter.html?items=$1 [NC]
BEFORE
RewriteCond %{REQUEST_FILENAME} !-f
So it should looks like:
Code:
##
# Rewrite base
##
RewriteEngine On
#Options +FollowSymlinks
RewriteBase /
##
# Block malicious requests
##
RewriteCond %{REQUEST_URI} (ftp|https?):|/etc/ [NC,OR]
RewriteCond %{QUERY_STRING} (ftp|https?):|/etc/ [NC]
RewriteRule .* - [F,L]
##
# Compress .js and .css files
##
AddEncoding gzip .gz
AddType "text/javascript" .gz
AddType "text/css" .gz
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME} \.(js|css)$
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule ^(.*)$ $1.gz [L]
##
# Rewrite TYPOlight URLs
##
RewriteCond %{REQUEST_URI} nyheter/(.*)\.html$
RewriteRule ^nyheter/(.*)\.html$ nyheter.html?items=$1 [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*\.html$ index.php [L]
3) Go to admin panel and create page named “nyheter” in site root. Make it visible for navigation and publish.
4) Go to template and create a duplicate news_full.tpl to news_full_latest.tpl
5) Delete all content from news_full_latest.tpl and place there:
Code:
<?php
if ($_SERVER['REQUEST_URI'] == '/nyheter.html')
{
header('Location: nyheter/'.$this->alias.'.html');
}
?>
6) Create a module (Newslist) named news_latest and select news_full_latest.tpl template for it.
7) Create module (Newsreader) news_reader and assign template for it (!!! Except news_full_latest.tpl)
8) Create article for nyheter page and place there 2 modules
1 - news_latest
2 – news_reader
And publish this article
That’s all.
P.s.
Sorry for my English.
Re: How to make short links in news?
@Dmitry
Thank you for the post of your findings!
Nyheter.. -er du fra Sverige? :D
I think they will be really useful for someone in here, but the thing i dont like is the change in the core module, which would be overwritten if updated, but i actually finds it pretty strange that we cant change that stuff in the settings? :S
I mean, take a look.. how stupid is this: http://www.en-dansk-side.dk/nyheder/ite ... nmark.html
Det ville være a bit like hvis jeg bare began at snakke engelsk in the midten af en sentence, right?
Re: How to make short links in news?
Quote:
Originally Posted by JimmyRittenborg
@Dmitry
Thank you for the post of your findings!
Nyheter.. -er du fra Sverige? :D
I think they will be really useful for someone in here, but the thing i dont like is the change in the core module, which would be overwritten if updated, but i actually finds it pretty strange that we cant change that stuff in the settings? :S
I mean, take a look.. how stupid is this:
Code:
http://www.en-dansk-side.dk/nyheder/items/saadan-fester-vi-i-danmark.html
Det ville være a bit like hvis jeg bare began at snakke engelsk in the midten af en sentence, right?
Re: How to make short links in news?
Hello! JimmyRittenborg!
I am sorry, but I don't speak Swedish and Norwegian. I'm from Ukraine. :(
I agree with you - this is a bad solutions, but it's only one which I found.
Sometimes you need to do something as quickly as you can, no matter how.... something like this dirty solution.
I think you agree with me :)
Re: How to make short links in news?
You can now use url cleaner to remove these "items" parts safely... Without having the core
Re: How to make short links in news?