Page 3 of 4

Re: Pretty URLS running .... but... one question!

Posted: Sun Feb 10, 2008 2:34 am
by giggler
Is there no way to make it www.domain.com/news/01/02/my-title-in-news, since I believe search engine takes the actual page url as more weight than the title being as if it's a directory

Re: Pretty URLS running .... but... one question!

Posted: Sun Feb 10, 2008 3:01 am
by nivekiam
I don't believe that about the order of your words in your URL bearing any weight on SE rankings, but yes, you can do that.

Take a look at what fritzfs and give it a try  ;D

For those who are lazy here it is (not the full solution, only the changes needed to be made from the solution fritzfs posted.  Do not blame me for any typos I make.  You also don't have to do the trailing slash stuff if you don't want to.

Edit file modules/News/action.default.php at about line 312 (it was 313 for me) and replace with this:

Code: Select all

$prettyurl = 'news/'.$row['news_id'].'/'.($detailpage!=''?$detailpage:$returnid).'/'.str_replace(' ', '-', $onerow->title);
Edit .htaccess file and set like this:

Code: Select all

# News
RewriteRule ^news/([0-9]+)/([0-9]+)/([A-Za-z0-9-]+)/?$ index.php?mact=News,cntnt01,detail,0&cntnt01articleid=$1&cntnt01returnid=$2 [L]
This exercise was great though as it's given me a little more insight into rewriterules and maybe one step closer to creating clean, friendly tag URLs for the tag module ;D

Re: Pretty URLS running .... but... one question!

Posted: Mon Feb 11, 2008 12:14 pm
by fritzfs
Yes, you can use my posted code and change the order of variables as nivekiam instructed.

Please notify me if you have any trouble getting it up & running.

Re: Pretty URLS running .... but... one question!

Posted: Tue Feb 19, 2008 12:26 am
by Lio
Hi !

Thanks for all these tips :)
But what about the RSS feed ? How can i set the new url into ? We need a Smarty tag (the link with keywords) which doesn't exist !


Good night.
Lio.

Re: Pretty URLS running .... but... one question!

Posted: Thu Feb 21, 2008 2:05 am
by LeeUmm
Great tip.

It worked great for me, except I added in the strtolower function to make sure the clean URL was in all lower case letters. When taking the news title, more than likely there will be some capital letters for when you Write Headlines Like This. It's better practice to not include capital letters in the URL and it will match the rest of your site URL structure by default.

Code: Select all

$prettyurl = 'news/'.str_replace(' ', '-', strtolower($onerow->title)).'/'.$row['news_id'].'/'.($detailpage!=''?$detailpage:$returnid);
I haven't had much time to dig further for tonight, but is there a way to display clean URLs for category listings? And a step further would be to include the option to have clean URLs for the pagination links too.

Re: Pretty URLS running .... but... one question!

Posted: Fri Feb 22, 2008 7:04 pm
by hillel213
The page URL's work great.  They are now more SEO friendly.

However, I am having trouble with the NEWS.

The News URL looks nice when I scroll over it:

http://www.example.com/news/Smile-South ... stry/2/15/

But, when I click on it, I get a 500 Internal Server Error.

If I change the action.default.php in the modules/news/ folder to...

$prettyurl = ''.str_replace(' ', '-', $onerow->title).'/'.$row['news_id'].'/'.($detailpage!=''?$detailpage:$returnid);
 
... it will go to the url without the news folder (http://www.example.com/Smile-South-Flor ... stry/2/15/), but it will display the home page.

So, I think it has something to do with the News Tag in my .htaccess file:

# News
RewriteRule ^news/([A-Za-z0-9-]+)/([0-9]+)/([0-9]+)/?$ index.php?mact=News,cntnt01,detail,0&cntnt01articleid=$2&cntnt01returnid=$3 [L]

Any insights?

Thanks,

Alex

Re: Pretty URLS running .... but... one question!

Posted: Fri Feb 22, 2008 7:43 pm
by nivekiam
You didn't follow the instructions ;)

Since you went off path and removed the /news from the URL, you need to remove that from the rewrite rule:

Code: Select all

# News
RewriteRule ^([A-Za-z0-9-]+)/([0-9]+)/([0-9]+)/?$ index.php?mact=News,cntnt01,detail,0&cntnt01articleid=$2&cntnt01returnid=$3 [L]
I don't know if that solve the problem, but that's where I'd start.  If that doesn't fix it, please post all your rewrite rules and any other changes you made and put them in a code block (click the little # button when creating your post) so your code doesn't wrap the screen and we can see exactly what you have.  Notice, how the rewrite rule I posted doesn't wrap the line.

Re: Pretty URLS running .... but... one question!

Posted: Fri Feb 22, 2008 11:13 pm
by hillel213
Wow!!!  You are awesome!  Thank you so much.

Here is my .htaccess:

Code: Select all

# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

# News
RewriteRule ^([A-Za-z0-9-]+)/([0-9]+)/([0-9]+)/?$ index.php?mact=News,cntnt01,detail,0&cntnt01articleid=$2&cntnt01returnid=$3 

[L]

# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
How do I add the news element?  I tried before, but got an error.

In action.default.php, I put

Code: Select all

$prettyurl = 'news/'.str_replace(' ', '-', $onerow->title).'/'.$row['news_id'].'/'.($detailpage!=''?$detailpage:$returnid);
I put

Code: Select all

# News
RewriteRule ^news/([A-Za-z0-9-]+)/([0-9]+)/([0-9]+)/?$ index.php?mact=News,cntnt01,detail,0&cntnt01articleid=$2&cntnt01returnid=$3 

[L]
in the .htaccess...

BUT, I got a 500 Internal Server Error.

The suggestion you made worked, but I could not apply it to the situation when I add the news directory.

What do you think?

Thanks, again!

Alex

Re: Pretty URLS running .... but... one question!

Posted: Sat Feb 23, 2008 12:16 am
by nivekiam
Well I'm not rewrite expert, far from it, but it's really easy to make typos and generate 500 server errors...

The only difference I can see in what you posted versus what I posted is you don't have [L] on the same line as your RewriteRule

(scroll all the way to the right)
Yours

Code: Select all

RewriteRule ^news/([A-Za-z0-9-]+)/([0-9]+)/([0-9]+)/?$ index.php?mact=News,cntnt01,detail,0&cntnt01articleid=$2&cntnt01returnid=$3 


[L]

(scroll all the way to the right)
What I posted

Code: Select all

RewriteRule ^news/([A-Za-z0-9-]+)/([0-9]+)/([0-9]+)/?$ index.php?mact=News,cntnt01,detail,0&cntnt01articleid=$2&cntnt01returnid=$3 [L]
I really don't know if that will make a difference or not, but it's worth a try.  I can't see anything else that's different.

Re: Pretty URLS running .... but... one question!

Posted: Sat Mar 08, 2008 5:43 pm
by loosefast
Just implementing this pretty url scheme for news and noticed that if news titles have a "." in them, it can break the link.

Anybody else notice that?

Tom

Re: Pretty URLS running .... but... one question!

Posted: Fri Mar 14, 2008 6:26 pm
by Zappa
I've tried the pretty url modification as Nivekiam has given instruction for but I have characters in the title of my news articles with special characters such as £, $, !. These special characters are showing in the url so is there a way how to strip out any characters which are not in the alphabet so you can have a url like /news/hello-world instead of /news/hello-world!

Thanks

Re: Pretty URLS running .... but... one question!

Posted: Fri Mar 14, 2008 7:45 pm
by nivekiam
This is the reason this hasn't been implemented natively in the News module.  Calguy1000 has posted about this someplace, it would be a lot of work.

I see 3 choices, do not use special characters, do not use this mod/hack, modify the news module to work with Pretty URLs, disallowing special characters in the titles or re-working it so it has an additional property of "alias".

Re: Pretty URLS running .... but... one question!

Posted: Fri Mar 14, 2008 8:37 pm
by calguy1000
The alias problem is a very common one.  You cannot re-use a 'Name' that may contain quotes, or funky non alphanumeric characters as  URL. 

The same applies with custom fields.  if you put special characters (or even spaces) into your custom field names, then you may have problems with templating, and a whole host of other issues.

To properly fix these problems, and to put some text that resembles the article name on the URL will require a significant amount of effort (particularly testing, that's always a pain in the ass) by somebody that is familiar with PHP, and familiar with the module api.

Hence, the news module doesn't support these pretty urls.  It's on my todo list, but paying projects and CMS 2.0 are higher on my priority list at the moment.

Re: Pretty URLS running .... but... one question!

Posted: Fri Mar 21, 2008 12:53 pm
by STW_andrew
Action.default.php
$prettyurl = 'news/'.$row['news_id'].'/'.($detailpage!=''?$detailpage:$returnid).'/'.str_replace(' ', '-', $onerow->title);
Was used with
# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

# News
RewriteRule ^news/([0-9]+)/([0-9]+)/([A-Za-z0-9-]+)/?$ index.php?mact=News,cntnt01,detail,0&cntnt01articleid=$1&cntnt01returnid=$2 [L]

# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
for pretty news urls and wile as a side effect, images refuse to display in news now.

If I go to this unpretty url you'll see the title header.
http://www.spottheweasel.com/index.php? ... eturnid=26

but when I try the prettied up url
http://www.spottheweasel.com/news/10/26 ... -Elements/

I just get the images titles, and when I go back into editing they show up. So I dunno what the solution is.

Re: Pretty URLS running .... but... one question!

Posted: Fri Mar 21, 2008 1:23 pm
by nivekiam
It's the way you are referring to that image.  Don't use "uploads/images/EE-large.jpg"  Either use "http://www.spottheweasel.com/uploads/im ... -large.jpg" or "/uploads/images/EE-large.jpg"

On this page, http://www.spottheweasel.com/news/10/26 ... -Elements/, the browser is looking for the image at:
http://www.spottheweasel.com/news/10/26 ... -large.jpg

Personally I always refer to images and pages on my site using absolute URLs, "http://www.spottheweasel.com/uploads/im ... -large.jpg".  A lot of people don't like doing that because that can create additional work depending on how you have your development environment setup.  But I use absolute URLs for my own reasons.