user2896120
user2896120

Reputation: 3282

.htaccess SEO friendly url

I am trying to create a SEO friendly URL for my home page. For example, I want example.com?url=hello-world to become example.com/hello-world. My current .htaccess has the following:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

It removes .php file extensions correctly, but how can I make it so that it can also generate a SEO friendly url for the home page? The file is index.php.

Upvotes: 2

Views: 2012

Answers (1)

Abhishek Gurjar
Abhishek Gurjar

Reputation: 7476

Try this,

RewriteEngine On

#remove .php    
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

#for pretty url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ index.php?url=$1 [NC,L]

Upvotes: 4

Related Questions