/    Sign up×
Community /Pin to ProfileBookmark

Mod_rewrite issuess..

I am using the following code:

RewriteEngine On
RewriteRule ^booksearch/([0-9A-Za-z]+)$ booksearch/booksearch.php?ISBN=$1
RewriteRule ^booksearch/([0-9A-Za-z]+).php$booksearch/booksearch.php?ISBN=$1

If I remove the second rule, it works and redirects url/booksearch/XXXXXX to booksearch.php?ISBN=XXXXXX.

I however also want url/booksearch/XXXXXX.php to load up booksearch.php?ISBN=XXXXXX

I have tried multiple different ways of writing it, but can’t seem to find the solution.

Any help?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@Kostas_ZotosSep 13.2007 — Hi,

I think is better to combine the 2 rules in one expression. For example to write something like this:

RewriteEngine On

RewriteRule ^booksearch/([0-9A-Za-z]+)(.php)?$ booksearch/booksearch.php?ISBN=$1

Note: the ? quantifier in regex (.php)? makes the ".php" optional (to exist once or not at all) so both cases normally should fit.

Kostas
Copy linkTweet thisAlerts:
@smartboybyndauthorSep 14.2007 — Nope, still doesn't work.

Here is the code in my .htaccess file:


AddType application/x-httpd-php5 .php

RewriteEngine On

RewriteRule ^booksearch/([0-9A-Za-z]+)(.php)?$booksearch/booksearch.php?ISBN=$1

The following code does work, except just for booksearch/ISBN, not Booksearch/isbn.php:



RewriteEngine On

RewriteRule ^booksearch/([0-9A-Za-z]+)$ booksearch/booksearch.php?ISBN=$1
Copy linkTweet thisAlerts:
@Kostas_ZotosSep 16.2007 — Just an assumption: [B]did you leave a space between the 2 parts in your rule?[/B]

(you need this space -between "..$ booksearch.."- to separate the parts: the match pattern and the target)

[B]You wrote the rule without a space:[/B]
RewriteRule ^booksearch/([0-9A-Za-z]+)(.php)?[COLOR="Purple"]$b[/COLOR]ooksearch/booksearch.php?ISBN=$1[/QUOTE]

[B]Try this (Just use a space after the first $ -from left- to separate the 2 rule parts):[/B]

RewriteRule ^booksearch/([0-9A-Za-z]+)(.php)?$ booksearch/booksearch.php?ISBN=$1

[B]Or use more parentesis, [COLOR="Navy"](note the use of $2 back-reference in this case):[/COLOR][/B]

RewriteRule ^booksearch/(([0-9A-Za-z]+)(.php)?)$ booksearch/booksearch.php?ISBN=[B][COLOR="Navy"]$2[/COLOR][/B]
×

Success!

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