• Hi,
    because of a problem in the rewrite rules that WordPress generates
    (nextpage feature results in 404 error because a rewrite rule is too
    greedy) I’ve tried to edit the htaccess file, by changing an existing
    rule and be adding a new one.
    Unfortunately, this results in a 500 internal server error and the
    only information a get in the server log is:
    File does not exist: /home/myserver/public_html/500.shtml

    I’ve posted the full (unmodified) htaccess below, but the following
    is the rule in question:
    RewriteRule ^(.+)/([^/]+)(/[0-9]+)?/?$ /digitalcamera/index.php?category_name=$1&name=$2&page=$3 [QSA,L]

    As I said, this rule does not work as it should and will not put any
    page number in $3, because the first .+ is too greedy.
    I tried to solve this by changing this rule and adding another rule
    just below the existing rule:
    RewriteRule ^(.+)/([^/]+)/([0-9]+)/?$ /digitalcamera/index.php?category_name=$1&name=$2&page=$3 [QSA,L]
    RewriteRule ^(.+)/([^/]+)/?$ /digitalcamera/index.php?category_name=$1&name=$2&page=$3 [QSA,L]

    I’ve tested the rules seperately (outside of wordpress in a regex
    editor) and they seem to work, however as soon as I upload the modifided
    htaccess I get the 500 internal server error.

    Does anyone know how to successfully modfiy the htaccess without generating
    an error?

    Thanks.

    Steve

    The unmodified htaccess:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /digitalcamera/
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [S=44]
    RewriteRule ^(contact-us)/trackback/?$ /digitalcamera/index.php?pagename=$1&tb=1 [QSA,L]
    RewriteRule ^(contact-us)/feed/(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?pagename=$1&feed=$2 [QSA,L]
    RewriteRule ^(contact-us)/(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?pagename=$1&feed=$2 [QSA,L]
    RewriteRule ^(contact-us)/page/?([0-9]{1,})/?$ /digitalcamera/index.php?pagename=$1&paged=$2 [QSA,L]
    RewriteRule ^(contact-us)(/[0-9]+)?/?$ /digitalcamera/index.php?pagename=$1&page=$2 [QSA,L]
    RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?&feed=$1 [QSA,L]
    RewriteRule ^(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?&feed=$1 [QSA,L]
    RewriteRule ^page/?([0-9]{1,})/?$ /digitalcamera/index.php?&paged=$1 [QSA,L]
    RewriteRule ^comments/feed/(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?&feed=$1&withcomments=1 [QSA,L]
    RewriteRule ^comments/(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?&feed=$1&withcomments=1 [QSA,L]
    RewriteRule ^comments/page/?([0-9]{1,})/?$ /digitalcamera/index.php?&paged=$1 [QSA,L]
    RewriteRule ^search/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?s=$1&feed=$2 [QSA,L]
    RewriteRule ^search/(.+)/(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?s=$1&feed=$2 [QSA,L]
    RewriteRule ^search/(.+)/page/?([0-9]{1,})/?$ /digitalcamera/index.php?s=$1&paged=$2 [QSA,L]
    RewriteRule ^search/(.+)/?$ /digitalcamera/index.php?s=$1 [QSA,L]
    RewriteRule ^category/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?category_name=$1&feed=$2 [QSA,L]
    RewriteRule ^category/(.+)/(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?category_name=$1&feed=$2 [QSA,L]
    RewriteRule ^category/(.+)/page/?([0-9]{1,})/?$ /digitalcamera/index.php?category_name=$1&paged=$2 [QSA,L]
    RewriteRule ^category/(.+)/?$ /digitalcamera/index.php?category_name=$1 [QSA,L]
    RewriteRule ^author/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?author_name=$1&feed=$2 [QSA,L]
    RewriteRule ^author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?author_name=$1&feed=$2 [QSA,L]
    RewriteRule ^author/([^/]+)/page/?([0-9]{1,})/?$ /digitalcamera/index.php?author_name=$1&paged=$2 [QSA,L]
    RewriteRule ^author/([^/]+)/?$ /digitalcamera/index.php?author_name=$1 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?year=$1&monthnum=$2&day=$3&feed=$4 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?year=$1&monthnum=$2&day=$3&feed=$4 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$ /digitalcamera/index.php?year=$1&monthnum=$2&day=$3&paged=$4 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$ /digitalcamera/index.php?year=$1&monthnum=$2&day=$3 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?year=$1&monthnum=$2&feed=$3 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?year=$1&monthnum=$2&feed=$3 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$ /digitalcamera/index.php?year=$1&monthnum=$2&paged=$3 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/?$ /digitalcamera/index.php?year=$1&monthnum=$2 [QSA,L]
    RewriteRule ^([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?year=$1&feed=$2 [QSA,L]
    RewriteRule ^([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?year=$1&feed=$2 [QSA,L]
    RewriteRule ^([0-9]{4})/page/?([0-9]{1,})/?$ /digitalcamera/index.php?year=$1&paged=$2 [QSA,L]
    RewriteRule ^([0-9]{4})/?$ /digitalcamera/index.php?year=$1 [QSA,L]
    RewriteRule ^(.+)/([^/]+)/trackback/?$ /digitalcamera/index.php?category_name=$1&name=$2&tb=1 [QSA,L]
    RewriteRule ^(.+)/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?category_name=$1&name=$2&feed=$3 [QSA,L]
    RewriteRule ^(.+)/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?category_name=$1&name=$2&feed=$3 [QSA,L]
    RewriteRule ^(.+)/([^/]+)/page/?([0-9]{1,})/?$ /digitalcamera/index.php?category_name=$1&name=$2&paged=$3 [QSA,L]
    RewriteRule ^(.+)/([^/]+)(/[0-9]+)?/?$ /digitalcamera/index.php?category_name=$1&name=$2&page=$3 [QSA,L]
    RewriteRule ^(.+)/feed/(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?category_name=$1&feed=$2 [QSA,L]
    RewriteRule ^(.+)/(feed|rdf|rss|rss2|atom)/?$ /digitalcamera/index.php?category_name=$1&feed=$2 [QSA,L]
    RewriteRule ^(.+)/page/?([0-9]{1,})/?$ /digitalcamera/index.php?category_name=$1&paged=$2 [QSA,L]
    RewriteRule ^(.+)/?$ /digitalcamera/index.php?category_name=$1 [QSA,L]
    </IfModule>

Viewing 5 replies - 1 through 5 (of 5 total)
  • It may be because in your second rule, there is no 3rd regex match (i.e. something in the $3 variable).

    So, this:
    RewriteRule ^(.+)/([^/]+)/?$ /digitalcamera/index.php?category_name=$1&name=$2&page=$3 [QSA,L]

    should be this:

    RewriteRule ^(.+)/([^/]+)/?$ /digitalcamera/index.php?category_name=$1&name=$2 [QSA,L]

    Just a guess.

    Thread Starter chemoul

    (@chemoul)

    Thanks for the reply VaamYob, I tried it but it doesn’t make a
    difference unfortunately.

    I don’t understand why adding an additional rewrite rule would cause
    an error 500.

    Steve

    Do you have access to the server logs ?

    Thread Starter chemoul

    (@chemoul)

    The only access I have is an error log through my cpanel. As I said
    above the only error message I get is:
    File does not exist: /home/myserver/public_html/500.shtml

    Steve

    The server is looking for a 500.shtml because it’s been told to show that file whenever a 500 error occurs.

    Can you contact your host and ask them for a copy of your logs ?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘try to add custom rule to htaccess = server error?’ is closed to new replies.