/    Sign up×
Community /Pin to ProfileBookmark

.htaccess rewrite rule.

I’m trying to do a rewrite for my shopping cart.

I have this

“`
RewriteRule ^cart cart.php
RewriteRule ^cart-details cart-details.php
“`

But my cart-details.php page rewrites to cart.php

I’ve also had [NC,L] and [NC] previously but that makes no difference.

Any ideas? I’ve never used these before

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 27.2020 — Maybe you need a $ at the end as the end-of-string assertion (the corollary to the ^ start-of-string assertion)? Or you might be able to do it with one condition for anything starting with "cart":
<i>
</i>RewriteRule ^(cart[^./]*)$ $1.php
Copy linkTweet thisAlerts:
@kiwisauthorJul 27.2020 — I'm a completely lost with these.

I have another page. I want the URL to look like "/booking-confirmation" but the actual page is third-form-page.php

I thought it would be RewriteRule ^booking-confirmation third-form-page.php

But even when I try RewriteRule ^(booking-confirmation[^./]*)$ $1.php It still fails, I get 404 error page

What's this called and how can I understand what requirements are needed.
Copy linkTweet thisAlerts:
@NogDogJul 27.2020 — If it's a different name, then the wildcard with the $1 won't do it. You'd have to give the explicit target. However, I'm no expert at this...haven't had to deal with it in years. [This page](https://cwiki.apache.org/confluence/display/HTTPD/RewriteRule) has its examples include the leading slash, so maybe you need:
<i>
</i>RewriteRule ^/booking-confirmation /third-form-page.php [L]

The [L] says that if this pattern matches, do the rewrite and don't bother looking at any other patterns.
×

Success!

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