HI,
Given the following apache/mod_rewrite rule taken from .htaccess within minify directory on the server:
RewriteRule ^([a-z]=.*) index.php?$1 [L,NE]
what will be the nginx compatible equivalent of it? I have tried:
rewrite ^/minify/([a-z]=.*) minify/index.php?$1 break;
but that doesn't seem to work.
Any ideas guys?
I have something like this and it's working for me
rewrite ^/min/([a-z]=.*) /min/index.php?$1 last;
Try something more like bbPress's code.
Related
I want to point:
www.reneebuller.com/paintings/busy-pair-humming-bird-painting.html to
www.reneebuller.com/painting-details.cfm?ID=136&Type=Bird
Is this the correct rewrite? I'm not sure how to account for the /paintings/ folder.
RewriteRule ^paintings/busy-pair-humming-bird-painting.html painting-details.cfm?ID=136&Type=Bird [NC, R=301, L]
The above rewrite is correct. It just takes time for the server to process the .htaccess file.
I want to make the following url in nginx
comments.php?id=34
becomes
/comments/34
/comments/34/
I am trying with this and it works
rewrite ^/comments/$id/(.*)$ /comments.php?id=$1? last;
My Question is, how to do I force redirect comments.php?id=x to /comments/id
rewrite ^/comments.php$ /comments/$arg_id? permanent;
According to the documentation, "rewrite operates only on path, not parameters."
Try this instead:
if ($args ~ id=(.+)){
rewrite comments\.php /comments/$1 last;
}
I have a URL:
"http://www.lootza.com/Model/Public/BuyNow/buynow.php?str=NDA="
I want to re-write this url as below:
"http://www.lootza.com/buynow/NDA="
I tried to do this by writing this below code in .htaccess but not getting any luck.
RewriteEngine on
RewriteRule ^$ /Model/Public/Home/
RewriteRule ^buynow/([0-9]+)/?$ Model/Public/BuyNow/buynow.php?str=$1
Please give me write syntax.
Regards
That seems correct assuming NDA= is an numeric string.
You can use the following to speed up your future test cycles:
http://civilolydnad.se/projects/rewriterule/
I'm trying use mod_rewrite to rewrite URLs from the following:
http://www.site.com/one-two-file.php
to
http://www.site.com/one/two/file.php
The folders don't exist, but "virtually" exist for the rewriting purpose.
What rule do I used in this?
Untested:
RewriteRule ^([^/]+)/([^/]+)/([^/]+)\.php$ $1-$2-$3.php [L]
I can't really understand your explanations about virtuality and existence: one-two-file.php must exist or you'll have nowhere to redirect to.
Update
The previous version works fine when used from an .htaccess file. However, if used from main http.conf file you need to add leading slashes:
RewriteRule ^/([^/]+)/([^/]+)/([^/]+)\.php$ /$1-$2-$3.php [L]
I presume that's why it wasn't working for the OP (he was probably getting a 404 not found status code).
My .htaccess file currently looks like this
AddType x-mapp-php5 .php
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^account$ /account/orders.php [L]
When I go to http://mywebsite.com/account it properly shows the page at http://mywebsite.com/account/orders.php. But when I change the RewriteRule to
RewriteRule ^account/orders$ /account/orders.php [L]
and then I go to http://mywebsite.com/account/orders, I get Error 404 Page Not Found. What did I do wrong?
******Additional Details**
I finally diagnosed the problem. But I don't understand why my solution works. Consider the scenario where account/orders.php exists.
The following rule will not work
RewriteRule ^account/orders$ account/orders.php [L]
The following rule will work
RewriteRule ^account/order$ account/orders.php [L]
Ie., the rewrite rule will fail if the Pattern evaluates to an existing file. So when the pattern is the same as the substitution, but minus the extension, the rewrite rule will fail. If I add a file called account/order.php, then both rules will fail.
Why does this happen?
I don't see how your first example would work, because I believe that intial slashes are also passed on.
RewriteRule ^/account/orders$ /account/orders.php [L]
Have you tried a relative path?
RewriteRule ^account/orders$ account/orders.php [L]
Edit You should also make sure to have MultiViews disabled. This causes that Apache does some additional vague file matching to find similar named files and thus /account/orders would be mapped to /account/orders.php before it’s passed to mod_rewrite.
Strange, it seems ok to me...
If you have access to Apache Configuration try to enable RewriteLog and RewriteLogLevel for some debug...
Also take a look in the site's log files (always if you have access)
I would at first try to add a redirect to my rules, so I can see in the browser what is happening on the server.
RewriteRule ^account$ /account/orders.php [L,R]
Also make sure that there are no other rules (previous ones) interfering, just in case you are not showing all of your .htaccess file here.
I'm answering my own question because I finally diagnosed the problem. But I don't understand why my solution works. Consider the scenario where account/orders.php exists.
The following rule will not work
RewriteRule ^account/orders$ account/orders.php [L]
The following rule will work
RewriteRule ^account/order$ account/orders.php [L]
Ie., the rewrite rule will fail if the Pattern evaluates to an existing file. So when the pattern is the same as the substitution, but minus the extension, the rewrite rule will fail. If I add a file called account/order.php, then both rules will fail.
Why does this happen?