mod-rewrite
RewriteRule Last [L] flag not working?
The [L] rule works fine — you just do not know how it actually works. When Apache sees the [L] flag and rule matches (rewrite occurs), Apache will go to next iteration and will start matching all rules again from top. The [L] flag means “do not process any rules below in this iteration“. Yes, … Read more
404 Not Found The requested URL was not found on this server
In Ubuntu I did not found httpd.conf, It may not exit longer now. Edit in apache2.conf file working for me. cd /etc/apache2 sudo gedit apache2.conf Here in apache2.conf change <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> to <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>
Best Practice: 301 Redirect HTTP to HTTPS (Standard Domain)
To start with your favorite solution: <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L] </IfModule> In the part handling non-https URLs you are redirecting to %{HTTP_HOST}. Then, in case your host name started with “www”, a second redirect has to take place to send … Read more
mod_rewrite RewriteCond – is NC flag necessary for just domain part? And some more
Having [NC] is definitely not mandatory but it is recommended to have it for matching domains. Modern browsers might be converting domain names to lowercase but what about old browsers and command line utils like wget, curl etc, so you should not always rely on clients sending you lowercase domain name and keep [NC]. About … Read more
How to use .htaccess in WAMP Server?
Click on Wamp icon and open Apache/httpd.conf and search “#LoadModule rewrite_module modules/mod_rewrite.so”. Remove # as below and save it LoadModule rewrite_module modules/mod_rewrite.so and restart all service.
How can I mod_rewrite and keep query strings?
You need to add the [QSA] flag (“query string append”) RewriteRule ^apps/([A-Za-z0-9-_]+)/?$ index.php&app=$1 [L,QSA] For page 301 redirects with the [R] flag as opposed to internal rewrites like this one, the query string is automatically appended. However, you must force it with [QSA] for the internal rewrite.
Redirect to Apache built-in 404 page with mod_rewrite?
You can use the R flag on the RewriteRule to force a redirect with a given status code: While this is typically used for redirects, any valid status code can be given here. If the status code is outside the redirect range (300-399), then the Substitution string is dropped and rewriting is stopped as if … Read more
mod_rewrite with spaces in the urls
Try putting a \ in front of your space to escape it. RewriteRule ^article/with\ spaces.html$ /article/without_spaces.html [R=301,L]
AH10411 error: Managing spaces and %20 in apache mod_rewrite
(I tried $1%20$2 at the end, which also went badly). This looks like a bug. Encoding the space as %20 in the query string should be valid. You can also encode the space as + in the query string (as in your workaround). In your original rule, Apache should be encoding the space (as %20) … Read more