Htaccess: add/remove trailing slash from URL

Right below the RewriteEngine On line, add: RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [L,R] # <- for test, for prod use [L,R=301] to enforce a no-trailing-slash policy. To enforce a trailing-slash policy: RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*[^/])$ /$1/ [L,R] # <- for test, for prod use [L,R=301] EDIT: commented the R=301 parts because, as explained … Read more

Do you have to restart apache to make re-write rules in the .htaccess take effect?

A restart is not required for changes to .htaccess. Something else is wrong. Make sure your .htaccess includes the statement RewriteEngine on which is required even if it’s also present in httpd.conf. Also check that .htaccess is readable by the httpd process. Check the error_log – it will tell you of any errors in .htaccess … Read more

.htaccess – how to force “www.” in a generic way?

I would use this rule: RewriteEngine On RewriteCond %{HTTP_HOST} !=”” RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTPS}s ^on(s)| RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] The first condition checks whether the Host value is not empty (in case of HTTP/1.0); the second checks whether the the Host value does not begin with www.; the third checks for HTTPS (%{HTTPS} … Read more

Hidden features of mod_rewrite

Where to place mod_rewrite rules mod_rewrite rules may be placed within the httpd.conf file, or within the .htaccess file. if you have access to httpd.conf, placing rules here will offer a performance benefit (as the rules are processed once, as opposed to each time the .htaccess file is called). Logging mod_rewrite requests Logging may be … Read more

Getting a 500 Internal Server Error (require() failed opening required path) on Laravel 5+ Ubuntu 14.04

Finally Overcame the problem It was not the .htaccess file that was the problem nor the index.php. The problem was on accessing the files and requiring permissions. For solving the problem i ran the following commands through terminal. sudo chmod -R 755 laravel_blog and then type below to allow laravel to write file to storage … Read more

how to use “AND”, “OR” for RewriteCond on Apache?

This is an interesting question and since it isn’t explained very explicitly in the documentation I’ll answer this by going through the sourcecode of mod_rewrite; demonstrating a big benefit of open-source. In the top section you’ll quickly spot the defines used to name these flags: #define CONDFLAG_NONE 1<<0 #define CONDFLAG_NOCASE 1<<1 #define CONDFLAG_NOTMATCH 1<<2 #define … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)