.htaccess: RewriteRule: bad flag delimiters

2019-09-07 15:11发布

Pulling my hair out over this one. I have the following .htaccess file that does some custom redirects in addition to Wordpress's default settings. When tested it on my local Wamp server it worked fine but after moving to production I'm not getting a RewriteRule: bad flag delimiters error in the server log and after a while the site even goes down with an internal server error

Any help would be appreciated. Thanks in advance!

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^rockford_weddings___welcome\.html$ /wedding/ [R=301,L]
RewriteRule ^blog/?$ /journal/ [R=301,L]
RewriteRule ^blog/(.*)$ /$1 [R=301,L]

RewriteRule ^portraitinvestment/?$ /portraitinvestment\.pdf [R=301,L]
RewriteRule ^weddinginvestment/?$ /weddinginvestment\.pdf [R=301,L]
RewriteRule ^holidaycards2014/?$ /holidaycards2014\.pdf [R=301,L]
</IfModule>

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

1条回答
倾城 Initia
2楼-- · 2019-09-07 15:55

It could be newline error or some charset.

Try this:

  1. Copy-paste your custom htaccess contents somewhere:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^rockford_weddings___welcome\.html$ /wedding/ [R=301,L]
    RewriteRule ^blog/?$ /journal/ [R=301,L]
    RewriteRule ^blog/(.*)$ /$1 [R=301,L]
    
    RewriteRule ^portraitinvestment/?$ /portraitinvestment\.pdf [R=301,L]
    RewriteRule ^weddinginvestment/?$ /weddinginvestment\.pdf [R=301,L]
    RewriteRule ^holidaycards2014/?$ /holidaycards2014\.pdf [R=301,L]
    </IfModule>
    
  2. Delete your .htaccess file from server

  3. Go to your wordpress admin panel and find Options -> Permalinks
  4. Save it. (it will regenerate .htaccess file)
  5. Test public site if it works
  6. Copy-paste your custom code start of your htaccess file
查看更多
登录 后发表回答