简体   繁体   中英

Remove .php extention from url working but seo friendly url not working

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM