for example:
www.site.com/your/blue
will redirect to... www.site.com/your/index.php?=blue
right now when someone types in www.site.com/your/blue it throws an error saying page does not exist. can anyone help me with this? thank you in advance.
Mod rewrite has to be used for this kind of redirects:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/?$ $1/index.php?page=$2 [L]
</IfModule>
This regex ensures a clean url is being passed to the site and works with or without a ending slash.
NB: Parameters passed to PHP need to have a name so I added page=
If you want it to work without any restriction (spaces will work)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)/?$ $1/index.php?page=$2 [L]
</IfModule>
Use mod rewrite:
RewriteEngine On
RewriteRule ^(.*)/(.*)/$ $1/index.php?p=$2 [L]
(I added p
as name of the query string, because it can't be empty)
Additionally, you can add the following lines of code between RewriteEngine On
and the rewrite rule to make sure there's a trailing slash (which is recommended):
# Add trailing slash
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ http://www.site.com/$1/ [R=301,L]