-3

Cuurent URL is https://www.website.com/colleges.php?id=NR%20School%20of%20Architecture

we want to change this URL into SEO friendly URL as like, https://www.website.com/colleges/NR-School-of-Architecture

we used this htaccess,but only the spaces were removed

RewriteEngine On
RewriteBase /
# replace all space by hyphen
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*?)(?:\+|%20|\s)+(.+?)\sHTTP [NC]
RewriteRule ^ %1-%2 [L,NE,R=302]

we used this htaccess to remove .php, it worked and .php was removed in the entire site.

But we dint get a seo freindly url like this, colleges/NR-School-of-Architecture

RewriteBase /
## 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]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]

kindly help us in achieving seo friendly url using htaccess

Thanks in advance.

Balaji
  • 1
  • 1
  • Have you done _any_ research and tried anything at all? A quick Google on "htaccess seo friendly url" gave me multiple hits and tutorials... – M. Eriksson Jul 13 '17 at 08:21
  • I'm voting to close this question as off-topic because it doesn't show any effort of trying to solve the issue themselves. – M. Eriksson Jul 13 '17 at 08:24
  • yes we tried with some htaccess codes, but it dint work – Balaji Jul 13 '17 at 08:37
  • Then you need to show us what you've tried and what happened. Like I mentioned in the first comment, there are multiple tutorials about this if you just Google. – M. Eriksson Jul 13 '17 at 08:39
  • the above htaccess removed only space, but it dint make it as a seo friendly url and also the database dint get connect with it, for that url – Balaji Jul 13 '17 at 08:46

1 Answers1

0

You will need to define the rewrite rules in a .htaccess file placed in your site document root location after you have confirmed that mod-rewrite is enabled

RewriteEngine On
RewriteBase /
RewriteRule ^home /index.php
Billu
  • 2,733
  • 26
  • 47