/    Sign up×
Community /Pin to ProfileBookmark

Quick mod rewrite question

I am trying to get mod_rewrite working on my server.

My address looks like this:
index.php?p=blog&article_id=83

I have had a look at some guides but can’t seem to get it to work with these two items in the link.

How can I rewrite this to something more seo friendly?

Thanks

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiApr 12.2009 — How do you want your URL to look? A basic example might be yoursite.com/blog/83:

RewriteRule ([a-zA-Z0-9-_]+)/([0-9]+)$ index.php?p=$1&article_id=$2

But of course it depends entirely on how you want your URL's structured. This doesn't make much of an improvement from an SEO perspective. It's hard to give examples without knowing what you want.
Copy linkTweet thisAlerts:
@DisfunctionalauthorApr 12.2009 — Thanks for the reply.

I managed to get a re-write rule working that changes the url to below:

blog/ef/blog-article/79/

It looks better but not great. What I really want to do is change it so my url of 'index.php?p=blog&article_id=83' is changed to the blog article heading. For example article 83 is called 'Clean out' so my url would be:

blog/ef/clean-out/

Not sure how I would get this to work though ?
Copy linkTweet thisAlerts:
@MindzaiApr 12.2009 — You won't be able to do this with mod_rewrite alone. You will need to store the slug in the database and use it to look up the article after rewrite has translated it to part of the query string (well this is one approach anyway, there are others). I usually just write a single rewrite rule to pass the entire requested location to index.php and just parse it all there, much easier. You would probably want to allow direct access to resources though:

<i>
</i>RewriteCond &amp;#37;{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?req=$1 [QSA,L]
×

Success!

Help @Disfunctional spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...