Maha Dev
Maha Dev

Reputation: 3965

Htaccess RewriteRule giving Internal Server Error

I am using htaccess RewriteRule rule for my site, I have tried it in two ways, first one is working while second is not working. Here is my code

Its working

RewriteRule ^article/(.*)$ /article-detail.php?slug=$1 [L]

Its not working (Just using folder)

RewriteRule ^article/(.*)$ /article/article-detail.php?slug=$1 [L]

Second way is giving internal server error. Can you help please.

Upvotes: 0

Views: 39

Answers (1)

anubhava
anubhava

Reputation: 784898

RewriteRule ^article/(.*)$ /article/article-detail.php?slug=$1 [L]

Your second rule is not working because your regex pattern is matching both source and target URLs which results in a rewrite loop and causes 500 error.

You can add a RewriteCond to prevent this behavior:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^article/(.+)$ article/article-detail.php?slug=$1 [L,QSA,NC]

Upvotes: 1

Related Questions