/    Sign up×
Community /Pin to ProfileBookmark

Php + rewrite rules – help required!

I was trying to rewrite some urls witht he following rule:

[CODE]RewriteRule ^([a-z0-9-]*)$ news.php?slug=$1[/CODE]

it works as long as i try site.com/title-goes-here

but it also means that any word a-z char and 0-9 typed after site.com will be taken as slug
so when i try to use this rule (also working before apply the ^ upper one)

[CODE]RewriteRule ^page$-([0-9]+)$ index.php?page=$1[/CODE]

which would output the site.com/page-3(or 4 or whatever)

i found a temporarely solution which helps the rule to “indicate” that only this type of urls should be received and “read” as slug

[CODE]RewriteRule ^test-([a-z0-9-]*)$ news.php?slug=$1[/CODE]

seems that the word test- helps to be read correctly so , when i try site.com/test-something-here
[b]something-here[/b] is “read” as slug,which is perfectly well,but i hate to add any extra words on my urls,so i was hopeing that you can help me solve this.

The result i am looking for is this:
rewrited url ————————— original url
site.com/some-title-of-the-news – site.com/news.php?slug=title-of-the-news (i don’t want to add any / chars e.g. sitem.com/news/tite-of-the-news if this is possible!)
site.com/page-1 – site.com/index.php?page=1
site.com/contactme – site.com/contactform.php

Thanks in advance!

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @wdas 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.20,
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,
)...