Jump to content

There MIGHT be a hyphen after this number...help?


br3nn4n

Recommended Posts

So I'm working on making my links SEO friendly.

 

I had links like so before...I have mod_rewrite on, obviously:

www.example.com/[b]articles/news/243[/b]

 

I want to include SEO friendly urls derived from the title of the article. I got a function to remove all the weird characters and quotes, etc from the article title, which means I can then make my links like so:

 

www.example.com/[b]articles/news/243-best-beaches-around-socal[/b]

 

Get the idea? It gives the article ID# and then the SEO friendly title.

 

-->MY PROBLEM arises wherein, I don't know how to tell mod_rewrite to grab the number from that url, but NOT the trailing hyphen (-) and any words after it (the SEO part, obviously). I JUST need the number so it knows what article to show.

 

I know this is more a mod_rewrite question, but it's based on regex so I figured someone could help :D

 

Hope that's the case...thanks in advance and please move this if it's in the wrong place.

I tried MadTechie's expression and it's still not resulting in a page; here's an actual url (obviously, minus my real domain):

 

www.site.com/articles/features/265-top-beaches-in-socal

 

I'm just getting a file not found with

^articles/([a-zA-Z0-9]+)/(\d+)*$

and then using $1 to tell it which page (ie: news) and $2 to tell it what article id.

 

Any ideas?

What are you forwarding to?

 

Plus your code isn't the same as MadTechies' since you have \d+ which is one or more numbers, but you then have a 0 or more repeat on the outside of that capture group.

 

^articles/([a-zA-Z0-9]+)/(\d+)[^\d]*$

 

 

Alright I added in that part...I was going off Crayon's statement about it not being necessary.

 

My entire rule is:

 

RewriteRule ^articles/([a-zA-Z0-9]+)/(\d+)[^\d]*$ index.php?page=$1&article=$2 [NC,L]

 

It still isn't working, and I did just try going to the query string version of the page manually (just to make sure my PHP script wasn't at all the problem).

 

Quick question -- using this regex it should match with a url such as just the number (265) or the SEO version (265-top-beaches-socal) right? Either one will work since it doesn't look for (or do anything with) anything after any number right?

It's just occured to me, I don't know if the mod_rewrite regular expression engine supports \d as a numeric reresentative. So try the longhand version.

 

RewriteRule ^articles/([a-zA-Z0-9]+)/([0-9]+)[^0-9]*$ index.php?page=$1&article=$2 [NC,L]

 

Plus, I suspect that will forward to index.php in the top level directory, is that the objective? Surely you want index.php inside the articles folder?

  • 2 weeks later...

It's just occured to me, I don't know if the mod_rewrite regular expression engine supports \d as a numeric reresentative. So try the longhand version.

 

RewriteRule ^articles/([a-zA-Z0-9]+)/([0-9]+)[^0-9]*$ index.php?page=$1&article=$2 [NC,L]

 

Plus, I suspect that will forward to index.php in the top level directory, is that the objective? Surely you want index.php inside the articles folder?

 

You rock man, that worked.

 

Re: the articles directory thing. That's just there for show, there is no articles directory. mod_rewrite takes care of that and uses the main index.php file in public_html. It's just to make things clearer about where you are on the site

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.