[Solved] rewrite url help please
Added by zuleman over 8 years ago
Im trying to setup cs-cart and I haven't been able to find any examples of how the rewrite rules need to be done for it and I have been searching for 2 weeks online.
I have an example for nginx of :
if ($http_host != "www.example.com") { rewrite ^ http://www.example.com$request_uri permanent; } rewrite /api/(.*)$ /api.php?_d=$1&ajax_custom=1 last; location ~ \.(png|gif|ico|swf|jpe?g|js|css|ttf|svg|eot|woff)$ { if (!-e $request_filename){ rewrite ^/(.*?)\/(.*)$ /$2 last; } expires 1w; } location ~ store_closed.html$ { if (!-e $request_filename){ rewrite ^/(.*?)\/(.*)$ /$2 last; } } location / { index index.php; try_files $uri $uri/ /index.php?sef_rewrite=1&$args; }
Ive been trying combo after combo of url.rewrite's in various flavors and I just can't get a combo that works.
Can anyone pleeeease show me how to do this in lighttpd. I have a bunch sites running flawlessly under lighttd and want to stick with it but I need to figure this out to keep using it.
Thanks in advance for any help on this.
Replies (12)
RE: rewrite url help please - Added by gstrauss over 8 years ago
Since the answers to the above can all be found in the lighttpd documentation, I seriously doubt you spent two weeks actually trying. If you've actually spent two weeks searching online, you must have found and tried some things. Please show what you have tried, rather than posting "do my work for me and convert this", which is essentially what you have posted above.
Docs_Configuration
Docs_ModIndexfile
Docs_ModExpire
Docs_ModRedirect
Docs_ModRewrite
RE: rewrite url help please - Added by zuleman over 8 years ago
# url.rewrite-once = ( "/api/(.*)$" => "/api.php?_d=$1&ajax_custom=1" ) # url.rewrite-once = ( "^/$" => "/index.php?route=common/home", url.rewrite-once = ( "^/$" => "/index.php?$1", "^/([^.?]*)\?(.*)$" => "/index.php?dispatch=$1&$2&$3", "/api/(.*)$" => "/api.php?_d=$1&ajax_custom=1" ) #"^/?dispatch/([0-9]+)$" => "/index.php?dispatch=$1", url.rewrite-if-not-file = ( "^/(.*)\.(css|js|jpg|png|gif)$" => "$0", "^/(.*)$" => "/index.php?$1" ) # "^/([^.?]*)\?(.*)$" => "/index.php?dispatch=$1&$2", # "^/(.*)" => "/index.php?_route_=$1" ) # "^/(.*)$" => "/index.php?$1" in place of _route_ tonight
I have been at it this for as long as I said. I freely admit I do not grasp the regex worth a flip.
That's why I have been trying variations hoping I would come up with a working solution. I have working rewrite setups
for other things but I can't find one that works 100% with cs-cart. That's why I decided to ask for help.
RE: rewrite url help please - Added by zuleman over 8 years ago
Not sure where the 1. and 2. etc came from but that's not in the code I pasted.
RE: rewrite url help please - Added by zuleman over 8 years ago
url.rewrite-once = ( "^/$" => "/index.php?$1", "^/([^.?]*)\?(.*)$" => "/index.php?dispatch=$1&$2&$3", "/api/(.*)$" => "/api.php?_d=$1&ajax_custom=1" ) url.rewrite-if-not-file = ( "^/(.*)\.(css|js|jpg|png|gif)$" => "$0", "^/(.*)$" => "/index.php?$1" )
This is pasted with all the remarked out code removed.
RE: rewrite url help please - Added by stbuehler over 8 years ago
Please wrap multi-line code with the "pre" button above (or manually using <pre>...</pre>
)
RE: rewrite url help please - Added by gstrauss over 8 years ago
- The url.rewrite directives do not include the query string. Try an outer match.
- The order of the rules matter, so I moved the /api/ rule earlier.
- Looks like you misinterpreted some of the regexes from the original.
This is untested, but will hopefully give you some ideas to try. I combined some things from the original and some from your subsequent post, so this is not expected to work with all your cases. Whether you want dispatch=... or sef_rewrite=1&... is up to you. After the outer match of $HTTP["query-string"] =~ "(.*)"
, what is in %1 (available for use in the rewrite target) is the same as nginx $args for the query string.
index-file.names = ( "index.php" ) $HTTP["host"] != "www.example.com" { $HTTP["query-string"] =~ "(.*)" { url.redirect = ( "(.*)" => "http://www.example.com$1?%1" ) } } else { $HTTP["url"] =~ "\.(?:png|gif|ico|swf|jpe?g|js|css|ttf|svg|eot|woff)$" { url.rewrite-if-not-file = ( "^/[^/]+(/.+)$" => "$1" ) expire.url = ( "" => "access plus 1 week" ) } else $HTTP["url"] =~ "store_closed.html$" { url.rewrite-if-not-file = ( "/[^/]+(/.*store_closed.html)$" => "$1" ) } else $HTTP["query-string"] =~ "(.*)" { url.rewrite-once = ( "^/(?:index.php|api.php)" => "", "/api/(.*)$" => "/api.php?_d=$1&ajax_custom=1", "(.*)" => "/index.php?dispatch=$1&%1" ) } }
RE: rewrite url help please - Added by zuleman over 8 years ago
I really appreciate you taking the time to do that. I will test it and post back the results. Thanks again !
RE: rewrite url help please - Added by zuleman over 8 years ago
It didn't work but I'm still trying to figure out why.
The url wasn't quoted at the end on the on two lines and the question mark in the extension check I removed at jpe?g. I still get an error at or near the start of the area with the first "url" check and I dont see why.
RE: rewrite url help please - Added by zuleman over 8 years ago
Its strange its giving a parse error at or near x line after {
Very vague.
So I tried remarking out everything and adding each section back in to see where the problem is. The www rewrite works fine. Everything after that fails even running each section individually.
The servers running 1.4.35 if that helps.
RE: rewrite url help please - Added by zuleman over 8 years ago
Ok redid it again and I can get each section to "run" individually if I remove all else statements.
Any of the else statements cause the next section to fail.
All of it will parse separately if there are no else statements involved. Each time I try it with the else between a statement if gives the parse error.
RE: rewrite url help please - Added by gstrauss over 8 years ago
I was missing quotes in $HTTP["url]
I have update the post. Should be $HTTP["url"]
Sorry.
RE: rewrite url help please - Added by gstrauss over 8 years ago
Yes, the 'else' without a condition is a feature of a more recent versions of lighttpd. lighttpd 1.4.35 is almost 3 years old!
You can replace
} else {
with
} else $HTTP["host"] == "www.example.com" {
(which is the opposite of the prior condition)