user273324
user273324

Reputation: 162

htaccess RewriteRule 500 error

Let's say I had this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^page(?:/error(?:/([^/]+))?)?/?$ page.php?error=$1 [L,QSA]

page/ and onwards (page/error/ etc) gives me a 500 error.

Upvotes: 0

Views: 112

Answers (1)

anubhava
anubhava

Reputation: 784918

You can use this rule to make last slash and other URI components optional:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^page(?:/error(?:/([^/]+))?)?/?$ page.php?error=$1 [L,QSA]

Full .htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^page(?:/error(?:/([^/]+))?)?/?$ page.php?error=$1 [L,QSA]

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

Upvotes: 1

Related Questions