Alex
Alex

Reputation: 47

how create clean urls using htaccess

Hi i want to create clean urls but my htaccess file does not create any effect.

Original url - http://example.com/abc/def/?page=1

required url - http://example.com/abc/def/page/1

I am using following htaccess file. I want to place this file in the def directory

RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ page?id=$1
RewriteRule ^([a-zA-Z0-9]+)/$ page?id=$1

Upvotes: 1

Views: 66

Answers (1)

hjpotter92
hjpotter92

Reputation: 80639

If def is indeed a directory, use the following inside it:

RewriteEngine On

RewriteCond %{THE_REQUEST} ^GET\ /(.+?)/?\?(page)=(\d+) [NC]
RewriteRule ^ %1/%2/%3? [R=301,L]

RewriteCond %{REQUEST_URI} ^/(.*)/page/(\d+)
RewriteRule ^(page)/(\d+)/?$ /%1/?page=$2 [NC,L]

Upvotes: 1

Related Questions