1

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 so
RewriteBase / 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!

1 Answer 1

1

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]
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the response. But this just redirects all URLs back to the home page and not the appropriate pages

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.