4
\$\begingroup\$

.htaccess is not my strong suit. Is there any there can optimize this code?

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(public)
RewriteRule (.*) /public/1ドル
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) 1ドル\.php [L]
ErrorDocument 500 "Sorry, our script crashed. Oh dear"
ErrorDocument 500 /cgi-bin/crash-recover
ErrorDocument 500 http://error.example.com/server_error.html
ErrorDocument 404 /errors/not_found.html
ErrorDocument 401 /subscription/how_to_subscribe.html

don't know if it necessary but here are an example of the folder system

  • app
  • public
    • index.php
    • contact.php
    • forum
      • last_news.php
      • users
        • user.php
      • ask.php
  • .htaccess
asked Mar 11, 2017 at 13:25
\$\endgroup\$

1 Answer 1

2
\$\begingroup\$
  1. Redundant RewriteEngine declarations
  2. Unused match group in (public)
  3. Escaping (using \) is not needed in the new URLs
  4. A personal touch, but I prefer to keep the core directives at the top, and put module specific directives inside <IfModule> body, so that I won't receive errors if the modules are disabled.
  5. Multiple declarations for ErrorDocument 500

Options +FollowSymLinks -MultiViews
ErrorDocument 401 /subscription/how_to_subscribe.html# Turn mod_rewrite on
ErrorDocument 404 /errors/not_found.html
ErrorDocument 500 http://error.example.com/server_error.html
<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteBase /
 RewriteCond %{REQUEST_URI} !^/(public)
 RewriteRule ^ /%1%{REQUEST_URI}
 RewriteCond %{REQUEST_FILENAME}.php -f
 RewriteCond %{REQUEST_URI} !/$
 RewriteRule ^(.*)$ 1ドル.php [L]
</IfModule>
answered Mar 19, 2017 at 10:08
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.