/    Sign up×
Community /Pin to ProfileBookmark

Help with RewriteEngine

I am having some complications with RewriteEngine

Here is my .htaccess file:

[code]
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^([^/]+)/$ index.php?section=$1 [L]
RewriteRule ^([^/]+)/([^/]+)$ index.php?section=$1&post=$2 [L]
[/code]

Basically, I want:

[url]www.myplainlife.com/rants/[/url]

to be /index.php?section=rants

and I want

[url]www.myplainlife.com/rants/Name_of_article[/url]

to be /index.php?post=Name_of_article

The way it is now, either one works or the other (if I swap the order of the rules), not both together. Also if the second rule is working, the images no longer show up on my site. Any one have any knowledge?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsAug 11.2005 — tryRewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule /([^./]+)/$ /path/to/index.php?section=$1 [PT]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule /([^/]+)/([^/]+)/?$ /path/to/index.php?section=$1&post=$2 [PT]
the best way to do this is to have the url like: http://www.myplainlife.com/section/rants/ and have "section" as your RewriteCond instead of -d
Copy linkTweet thisAlerts:
@chrysauthorAug 11.2005 — Yeah, what I ended up doing was this:

<i>
</i> RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^([^/]+)/$ index.php?section=$1 [L]
RewriteRule ^([^/]+).html$ index.php?post=$1 [L]


This way /section/ works and /Name_of_article.html works ?
Copy linkTweet thisAlerts:
@ShrineDesignsAug 11.2005 — good deal,

i did pretty much the same thing for a project i did a while back
Copy linkTweet thisAlerts:
@bokehAug 11.2005 — Why not just write proper URLs in the first place instead of using a query string?
×

Success!

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