I’m wanting to make a URL look pleasing to the eye.
from
/index.php?a=grapes
to
/grapes
Although, I’m having a few problems. I wanted a to have a wider variety of characters like a-z A-Z 0-9 / _ - . [ ].
from
/index.php?a=Grapes.Are.Green/Red[W4t3r-M3l0n_B1G_Gr4p3]
to
/Grapes.Are.Green/Red[W4t3r-M3l0n_B1G_Gr4p3]
In the index.php file I have
<?php
$a = $_GET["a"];
echo $a;
?>
just to test the URL is working correctly.
Right now what I have in .htaccess
RewriteEngine On
RewriteRule ^([a-zA-Z0-9/_]+)?$ index.php?a=$1
only accepts a-z A-Z 0-9 / _.
- If I add
-into the square brackets and have it as one of the
characters whichaequals I get the 404 error. - If I add
.into the square brackets I getindex.phpoutputted. - If I add
[or]I get the 404 error.
If anyone has a solution I’d love to see it. Also, if anyone has time please could you explain each part of the RewriteRule saying what the part does. Thanks!
The
[QSA]thing at the end is what made it work 🙂 Thanks to jedwards for suggesting to use^(.*)$which accepts all characters.