and you want to get rid of the .php at the end (that people only see signup and learnmore in their browsers and only have to type those in to get to the correct page)?
If true, you will only do a rewriteRule, and won’t use rewriteCond at all. Pls confirm?
is there any tutorial where i can understand more, 've been repeatedly reading and it just doesn’t click to me
http://datakoncepts.com/seo give that one a try. It’s written pretty simple or you can look around for the part that looks like it does what you’re after.
Then what you do is make the match more specific. The bad regex examples have
RewriteRule (.*)$ $1.php [R=301]
and the good ones might have
RewriteRule ^([^/][-a-zA-Z._]+)/?$ $1.php [R=301]
or something. Remember the first section is what you’re matching and because it might be many things, people use the regular expressions.
But in your case you really don’t want to match “any letters, dots, underscores”… you want to match
“learnmore” OR “signup” exactly.
From this point on, this is a guess… I’m not 100% certain if the pipe will be “or” this way…
RewriteRule ^(learnmore | signup)$ $1.php [R=301]
This means the real file is still learnmore.php or signup.php. You’re letting people either type in yoursite.com/learnmore and they’re getting silently redirected to yoursite.com/learnmore.php
etc
None of your other pages match those exact words so they will not go through the rewrite. If I did it right (Scallio would know better lawlz), then whatever’s matched, whether it’s learnmore or signup, gets added where the $1 is.
Agreed… [stuff in here] is generally one character to match, and the reason ([test1|test2]+) worked is the + which means “any number but at least one”, which kind of gets around that (in a way that you don’t want).
XTX and Sp have done a good job leading you in the correct direction. However, please let me stress a few points:
If you want a link which is not to a file, YOU must create that link, not mod_rewrite! signup is not a file nor is it a directory so it should draw a 404 error. mod_rewrite’s job is to redirect signup to signup.php (hidden) to give you the extensionless look of your URI (the same was that seo in http://datakoncepts.com/seo is an extensionless URI - it’s the seo.php script’s output which is presented to the visitor).
The above link is to the tutorial I created to preserve my wrists (repetitive typing - answering the same posts over and over and …).
A good specification is where you must always start: signup => signup.php and learnmore => learnmore.php should be sufficient. Those will tell you that NOT signup.php being redirected to signup.php is NOT what you want. It should be
RewriteRule ^/?signup$ signup.php [L]
Same with learnmore.
As suggested, these TWO RewriteRules can be combined very nicely with:
RewriteRule ^/?(signup|learnmore)$ $1.php [L]
Both XTX and Sp correctly removed the 's from your implementation as they are metacharacters used to create a character list whereas the ()'s create an atom. The pipe in the atom tells Apache to match the string before the pipe OR the string after the pipe (these can be chained if you have more extensionless links you want to use) and that becomes Apache’s $1 variable for the redirection.
NOTE: The ^/? is used because you did not let us know whether your server is Apache 1 (which requires ^/) or Apache 2 (which will NOT match the / so it requires only ^) - the ^/? can be used when you don’t know which version of Apache you’re using.