Hi,
I am new to php and have to do a project that consists of a joke page, a jokelist page and the front page or index page. My problem is this: I have used the text below in my .htaccess page and the only thing I get when I run the index.php file is the list of joke categories which is right but when i click on a category it produces an not found error.
I am so confused, please can someone help!
RewriteEngine On
RewriteRule^/jokespage$ index.php
mod_rewrite - can't figure this out!
Moderator: General Moderators
-
canadian_angel
- Forum Commoner
- Posts: 31
- Joined: Fri Jun 11, 2010 3:13 pm
Re: mod_rewrite - can't figure this out!
The rewrite rule you've made basically converts
http://www.domain.com/jokespage
to... http://www.domain.com/index.php
The ^...$ bit in the regular expression basically delimits the absolute start and end of the string.
So only anything that's exactly "jokespage" will match the rule, nothing more and nothing less.
But... http://www.domain.com/jokespage/ for example... will give you a 404 error because of the trailing /
To match "jokespage" or "jokespage/" you'll want your rule to be:
mod_rewrite uses regular expressions to match strings. As a programmer, it's something you'll want to learn.
I avoided learning regular expressions for years because they always looked so complicated but glad I made the effort, I end up using them loads now for data validation etc.
Take a look at this excellent tutorial written by one of our own... viewtopic.php?f=38&t=33147
Then get hold of this mod_rewrite cheat sheet... http://www.addedbytes.com/cheat-sheets/ ... eat-sheet/
And if you're on windows there's an excellent program which lets you test your regular expressions in real-time... The Regex Coach http://www.weitz.de/regex-coach/
Now on to your actual question...
What's the format of the URL that you want rewriting?
What's the destination of that URL?
Cheers, B
http://www.domain.com/jokespage
to... http://www.domain.com/index.php
The ^...$ bit in the regular expression basically delimits the absolute start and end of the string.
So only anything that's exactly "jokespage" will match the rule, nothing more and nothing less.
But... http://www.domain.com/jokespage/ for example... will give you a 404 error because of the trailing /
To match "jokespage" or "jokespage/" you'll want your rule to be:
Code: Select all
RewriteRule^jokespage/?$ index.phpI avoided learning regular expressions for years because they always looked so complicated but glad I made the effort, I end up using them loads now for data validation etc.
Take a look at this excellent tutorial written by one of our own... viewtopic.php?f=38&t=33147
Then get hold of this mod_rewrite cheat sheet... http://www.addedbytes.com/cheat-sheets/ ... eat-sheet/
And if you're on windows there's an excellent program which lets you test your regular expressions in real-time... The Regex Coach http://www.weitz.de/regex-coach/
Now on to your actual question...
What's the format of the URL that you want rewriting?
What's the destination of that URL?
Cheers, B