Author Topic: Modrewrite throws 500 error with php 5.6 but not with 7.x  (Read 4964 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
Modrewrite throws 500 error with php 5.6 but not with 7.x
« on: May 27, 2020, 01:58:09 PM »
I have one old site that I've not upgraded.  So I tried selecting php 5.6 for it.  But I get a 500 error and the logs show:
Quote
<snip>/public_html/.htaccess: RewriteRule: bad flag delimiters, referer: <snip>

On the same CWP server the exact same set of rules are working fine on another site running php 7.x. Therefore I conclude it is something related. This is the .htaccess file.  The actuual file name were replaced for this post:
Quote
AddHandler application/x-httpd-php56 .php

# AddType application/x-httpd-php .html .htm  #works on local host
AddType application/x-httpd-php .html .htm

# DirectoryIndex offline.html index.php
DirectoryIndex offline.html index.html index.php
RewriteEngine on



#ErrorDocument 404 /404.html


# rewrite base will need to be adjusted for use on server, most likely to /
# localhost on xammpp, when active dierctory is xampp/htdocs/dirname then RewriteBase needs /dirname/
# or just don't use it at all.  It seems to work fine without it also.
#RewriteBase /dirname/

# These are the problem lines

# rewites the script1.php URLs using / note the $3 is for the pagination
RewriteRule ^([0-9] )/(.*)-([0-9] )\.html$ script1.php?cat_id=$1&page=$3 [L,NC]


# rewrites the script2.php URLs using P- and /
RewriteRule ^P-([0-9] )/(.*)\.html$ script2.php?id=$1 [L,NC]

# rewrites the script3.php URLs
RewriteRule ^([0-9] )-(.*)\.html$ script3.php?id=$1 [L,NC]

Offline
****
Re: Modrewrite throws 500 error with php 5.6 but not with 7.x
« Reply #1 on: May 27, 2020, 02:16:23 PM »
Try adding RewriteCond %{REQUEST_URI} !/script\.php$
Google Hangouts:  rcschaff82@gmail.com

Offline
****
Re: Modrewrite throws 500 error with php 5.6 but not with 7.x
« Reply #2 on: May 27, 2020, 03:55:14 PM »
Additonal Info.  You really should Quote the Rule.  This should be your lines for ANY php version. As noted above, you should have a RewriteCond for each script?.php file so that you prevent apache from an endless loop.

RewriteRule "^([0-9] )/(.*)-([0-9] )\.html$ script1.php?cat_id=$1&page=$3" [NC,L]
# rewrites the script2.php URLs using P- and /
RewriteRule "^P-([0-9] )/(.*)\.html$ script2.php?id=$1" [NC,L]
# rewrites the script3.php URLs
RewriteRule "^([0-9] )-(.*)\.html$ script3.php?id=$1" [NC,L]
Google Hangouts:  rcschaff82@gmail.com