If this is my actual URL to a file:
In my .htaccess file, how can I use a regular expression to get to this path when a user submits:
So far I’ve come up with this bringing together a few examples (this also included a www redirect):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*) http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /$1.php [L]
RewriteRule ^posts/([A-Za-z])/$ /posts.php?post=$1
But I’m not having much luck with it, can anyone tell me where I’m going wrong?
You need a
+after yourA-Za-zgroup to indicate one or more characters, and also you need to add a-to the end of that group. At the end, the/?indicates that the final slash may or may not be present.Finally, add
[L]to be sure no further rewrite rules get processed.