Apache mod_rewrite for specific folders and paths Apache mod_rewrite for specific folders and paths apache apache

Apache mod_rewrite for specific folders and paths


I changed a little bit and it works perfectly

Changes

Remove the Change the RewriteRule to match file to .php to bottom.

Remove the $ sign that is End of the pattern

As Said in the update promote-1111 will redirect to promote.php?user=$1 change the promote-[0-9]+ to promote(-[0-9]+)? otherwise it will override in the second redirection as you redirecting it to promote.php?user=$1

The Code

RewriteCond %{HTTPS} offRewriteRule !^(surf|promote(-[0-9]+)?) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]RewriteRule ^([^.?]+)$ %{REQUEST_URI}.php [L]

The page surf

enter image description here

The Page Index

Never mind the error message shown in this image. Since I tried it from my localhost, it won't have a certificate.

Will work with servers

enter image description here


Your rules aren't in the "update" working because of side effects of using <Directory> context. Each substitution starts processing again.

When you request /promote-123 and rewrite it to put the numbers in the query string, you can't then match the numbers as if they're still in the path. You'll need to match the rewriten path and the numbers with RewriteCond %{QUERY_STRING} (if you care about the numbers)