0

I want to make seo friendly url using .htaccess.

I want to convert below url

http://localhost/projectname/pagename.php?id=1

to

http://localhost/projectname/pagename/1

I have already tried solution for this

RewriteRule ^pagename/([a-zA-Z0-9]+)/$ projectname/pagename.php?id=$1

But it's not working

I have also referred below links but not giving me right solution

How to write htaccess rewrite rule for seo friendly url

Creating SEO friendly urls using htaccess

.htaccess file

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

 RewriteRule ^pagename/([a-zA-Z0-9]+)/$ projectname/pagename.php?id=$1

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

using above htaccess file I can remove .php extention from url but not to generate seo friendly url.

Thank you a lot in advance.

Community
  • 1
  • 1
dhruv jadia
  • 1,684
  • 2
  • 15
  • 28

1 Answers1

0

You have a slash at the end of your rule, so you would have to go:

http://localhost/projectname/pagename/1/

Or change the rule to:

RewriteRule ^pagename/([a-zA-Z0-9]+)$ projectname/pagename.php?id=$1
sg-
  • 2,196
  • 1
  • 15
  • 16