br3nn4n Posted November 2, 2009 Share Posted November 2, 2009 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 Hope that's the case...thanks in advance and please move this if it's in the wrong place. Quote Link to comment Share on other sites More sharing options...
cags Posted November 3, 2009 Share Posted November 3, 2009 It's late and my mind has somewhat gone to mush, but I think you'd just need something like this... articles/news/([0-9]+)[-a-z]+ ... it does make certain assumptions, but nothing inaccurate I don't think. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted November 3, 2009 Share Posted November 3, 2009 ~Coughs @ cags~ * not + or articles/news/(\d+)[^\d]*$ Quote Link to comment Share on other sites More sharing options...
.josh Posted November 3, 2009 Share Posted November 3, 2009 if all you care about is that first set of digits you don't even need the rest of the expression. Quote Link to comment Share on other sites More sharing options...
br3nn4n Posted November 5, 2009 Author Share Posted November 5, 2009 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? Quote Link to comment Share on other sites More sharing options...
cags Posted November 5, 2009 Share Posted November 5, 2009 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]*$ Quote Link to comment Share on other sites More sharing options...
br3nn4n Posted November 5, 2009 Author Share Posted November 5, 2009 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? Quote Link to comment Share on other sites More sharing options...
cags Posted November 5, 2009 Share Posted November 5, 2009 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? Quote Link to comment Share on other sites More sharing options...
br3nn4n Posted November 15, 2009 Author Share Posted November 15, 2009 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 Quote Link to comment Share on other sites More sharing options...
cags Posted November 15, 2009 Share Posted November 15, 2009 Excellent, just FYI there is a 'Solved' button in the bottom left hand corner of a thread you start. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.