Reputation: 359
I have very little experience with PHP and using .htaccess, though I would like to create SEO-friendly URLs. I have scoured the internet and Stackoverflow searching for a problem similar to mine. I have tried multiple solutions but have had no luck and I am constantly met with errors.
So I have decided to create my own, although I am aware there may be a correct solution out there for me, I have been unable to find it.
This is how my URL currently appears www.site.com/?p=example
I would like it to appear as www.site.com/example
My .htaccess file is set up like soRewriteBase /
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
My index.php
file is set up like so http://puu.sh/ix8vV/33ff702e21.png
Help would be greatly appreciated as I have been trying this for hours to no avail.
Thanks in advance!
Upvotes: 1
Views: 263
Reputation: 785058
You will need an additional router rule to forward all non-file and non-directories to index.php
with a parameter p
:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+) ?p=$1 [L,QSA]
Upvotes: 1