简体   繁体   中英

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.

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]

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