I have a site that currently serves results as example.com/index.php?show=foo
and I’d like it to read example.com/show/foo.
My understanding is this would make them visible to search engine robots, and it seems a much simpler way to do this than to create a couple hundred html files…
I’ve tried the following .htaccess code:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^show/(.*)$ index.php?show=$1 [NC,L]
No dice.
Also tried this, which I found on another stack overflow question:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9A-Za-z]+)/?$ /index.php?show=$1 [L]
</IfModule>
Any ideas on what I’m missing here?
Note that
^([0-9A-Za-z]+)/?$will try to match a request URI that only includes alphanumeric characters optionally trailed by a slash. Therefore the URIshow/foowill not be matched because there are more characters at the end (ie, after the slash, where the expression expects to find the end of the string).Try:
RewriteRule ^show/([0-9A-Za-z]+)/?$ /index.php?show=$1 [L]Also, to capture aditional query parameters, you could do:
RewriteRule ^show/([0-9A-Za-z]+)/?$ /index.php?show=$1&%{QUERY_STRING} [L]This means a URL like
/show/page?id=1rewrites to/index.php?show=page&id=1