Dapo Michaels
Dapo Michaels

Reputation: 392

".htaccess" file not working at all

I have this code in my htaccess file

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}\.php !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC]

This help to remove the .php extension in my url. but now I've been trying for weeks to rename a URL I have.

article.php?num=5 to article/num/5 or maybe the title of the article it self nothing has worked so far. this is what I tried using.

RewriteRule ^article/([0-9].+)/?$   article?num=$1  [NC]

Yet I always get internal server error i really need help with this its been frustrating.

Upvotes: 1

Views: 51

Answers (2)

Amit Verma
Amit Verma

Reputation: 41249

Your RewritePattern doesnt accept the /num/ segment, you need to adjust it so it matches your your uri /article/num/digits . Change your pattern's regex to this

^article/num/([0-9]+)$

Upvotes: 2

Abhishek Gurjar
Abhishek Gurjar

Reputation: 7476

Try it like below rule,

Options +FollowSymLinks
RewriteEngine On

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

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)/num/([\d]+)$ $1.php?num=$1 [QSA,L]

Upvotes: 1

Related Questions