With mod_rewrite can I specify a RewriteBase within a RewriteCond?

The only solution we finally found looks like that : # Activation of the URL Rewriting Options +FollowSymlinks RewriteEngine On # RewriteBase equivalent – Production RewriteCond %{HTTP_HOST} !^localhost$ RewriteRule . – [E=REWRITEBASE:/production/path/] # RewriteBase equivalent – Development RewriteCond %{HTTP_HOST} ^localhost$ RewriteRule . – [E=REWRITEBASE:/development/path/] # Rewriting RewriteRule ^(.*)$ %{ENV:REWRITEBASE}index.php?page=$1 [L] This code offers a way … Read more

mod_rewrite urlencoding an already urlencoded query string parameter – any way to disable this?

the way to accomplish this is via the NE (no escape) paramater. RewriteRule ^something.swf$ http://www.newdomain.com/something.swf [R=302,L] should in fact read RewriteRule ^something.swf$ http://www.newdomain.com/something.swf [R=302,NE,L] this will force mod_rewrite to leave all query string values as they are, without doing any encoding / escaping. as easy as that 🙂

Set RewriteBase to the current folder path dynamically

Here is one way one can grab the RewriteBase in an environment variable which you can then use in your other rewrite rules: RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$ RewriteRule ^(.*)$ – [E=BASE:%1] Then you can use %{ENV:BASE} in your rules to denote RewriteBase, i.e.: #redirect in-existent files/calls to index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteRule . %{ENV:BASE}/index.php [L] Explanation: … Read more

The Redirection of Multiple Parked Domains doesn’t Work with Filename [closed]

If the questioner starts rewrite ruling with [R=301] 301 redirect, a.k.a. “Permanently Redirect”, and then he try to view his URL www.parkeddomain1.com/subfolder/ but the result of the rule wasn’t what he want, then even he try to change the redirecting rule, his web browser will always redirect that URL into the first URL where it … Read more

using mod_rewrite with XAMPP and windows 7 – 64 bit?

Below are the instructions on how to enable .htaccess mod_rewrite in xampp. Open and edit C:\xampp\apache\conf\httpd.conf in a text editor Find the line which contains #LoadModule rewrite_module modules/mod_rewrite.so and (uncomment) change to LoadModule rewrite_module modules/mod_rewrite.so Find all occurrences of AllowOverride None and change to AllowOverride All Restart xampp That’s it you should be good to … Read more

Apache rewrite rules not being applied for angularjs

This is now much easier in Apache 2.2.16+ using the FallbackResource directive. FallbackResource /app/index.html http://httpd.apache.org/docs/2.2/mod/mod_dir.html#fallbackresource Depending on how you’re forwarding access to your API you may need to also leverage the enclosure to disable the fallback resource on specifically on API requests (2.2.24+). <Directory /api> FallbackResource disabled </Directory>

How do I convert a PHP query string into a slash-based URL?

Simple .htaccess example: <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^lookup/([a-z0-9\-]+)/item/?$ /lookup.php?id=$1 </IfModule> This will match any alphanumeric (also will recognise dashes) string of any length as the ‘id’. You can limit this to just numeric by changing the regex to ([0-9]+). <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^lookup/([a-z0-9\-]+)/([a-z0-9\-]+)/?$ /lookup.php?id=$1&view=$2 </IfModule> This one will match /lookup/123/some-text/ to /lookup.php?id=123&view=some-text