I am not to sure where to put this post but this seemed like the best place.

I am currently writing scripts for page redirects, however, I can not get my .htaccess redirects working first.
I need to take from my root, and redirect to a subscript:

http://www.example.com -> /index.php
-> /pages/fetchpage.php?id=newpage

I have other RewriteRules already no problem, but when I add the following line:

RewriteRule ^(.*) pages/fetchpage.php?id=$1 [NC,L]

I get a server error:

500 Internal Server Error
Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, support@globat-inc.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

Globals:

RewriteBase         /
RewriteCond         %{HTTP_HOST}        ^tinyclark.com                              [NC]
RewriteRule         ^(.*)$                               [R=301,L]

And I also tried commenting out all other Rules in the event of conflicting rules, and still no change. I have seen the above example on numerous sites giving no one else problems.

Any and all help is greatly appreciated.
~tinyClark

Dani AI

Generated

Most likely cause: the rule that matched “everything” was creating an internal rewrite loop. When any request is rewritten to the fetch script, the same pattern can match that internally rewritten path again and again, and Apache eventually returns a 500. A 500 can also come from a syntax/permission problem (mod_rewrite disabled or certain directives not allowed in .htaccess), so the exact error.log entry is the authoritative clue.

A robust pattern that avoids the loop is to (a) skip existing files and directories, and (b) exclude requests that are already for the pages folder (or the fetch script) before rewriting slugs. Example (adapted to avoid repeating the original snippets in this thread):

# do not touch files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# ignore anything already under /pages/ and rewrite simple slugs only
RewriteCond %{REQUEST_URI} !^/pages/
RewriteRule ^([A-Za-z0-9_-]+)/?$ /pages/fetchpage.php?id=$1 [L,QSA]

Explanation: the first block leaves real assets (images, css, index.php) alone. The second block prevents the internally rewritten /pages/fetchpage.php from being rewritten again, and the slug-only pattern avoids matching multi-segment paths that could introduce complexity. The QSA flag preserves any incoming query string. Ordering matters: place canonical host redirects before or after these rules intentionally (test which order fits the desired behavior).

Practical checks: confirm mod_rewrite is available and .htaccess processing is allowed, and inspect Apache error logs (typical locations: /var/log/apache2/error.log or /var/log/httpd/error_log on many systems) for the exact failure message. As hinted, narrowing the match is the right direction; combining that with file/directory checks prevents the infinite-rewrite condition that causes the 500.

This should help:

RewriteEngine On
RewriteRule ^([^/]*)$ /pages/fetchpage.php?id=$1 [L]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.