apache second alias does'nt work - apache

I have an alias on apache like this: Alias “/images” “/home/user1/data” Now I want to have a second alias like this: Alias “/images/charts” “/home/user1/meta/output”
But it isn't working. How can I do this?

From the Documentation
(...) the Aliases and Redirects are processed in the order they appear in
the configuration files, with the first match taking precedence.
For this reason, when two or more of these directives apply to the
same sub-path, you must list the most specific path first in order for
all the directives to have an effect. For example, the following
configuration will work as expected:
Alias "/foo/bar" "/baz"
Alias "/foo" "/gaq"

Related

How do I enable query string in Cloudflare page rules?

I want to forward this URL
https://demo.example.com/page1?v=105
to
https://www.example.com/page1
It's not working if I set so:
But if I remove the ?v= part, it works:
Is there any way to include the ?v= part in this page rule?
The rule you mentioned works only for that exact URL: https://demo.example.com/page1?v=105. If it has any additional query parameter or even an additional character, eg https://demo.example.com/page1?v=1050, it won't match the rule.
If you need to use complicated URL matches that require specific query strings, you might need to use bulk redirects or a Cloudflare worker.

htaccess rewrite to reverse subfolders

As basic as it gets, here is an example of what I'm trying to do:
I have a structure that takes different types of CMS' and inside each of those installations, are language variations.
By default the structure looks like this:
https://[domain]/[country]/[installation]/[language-code]
Ultimately, I'm trying to get this:
https://[domain]/[country]/[language-code]/[installation]/
I'm wondering if this can be accomplished, due to the fact the folders/languages themselves are not actual folders and in fact rewrites from the CMS' settings (within the subfolders).
As unmodified these would be examples of the current urls:
https://example.com/ca/events/en/
https://example.com/ca/store/en/
https://example.com/ca/network/en/
And example of the desired results:
https://example.com/ca/en/events/
https://example.com/ca/en/store/
https://example.com/ca/en/network/
and for each installation, they dont always have the same languages (eg. ca has en and fr, but us has en and es)
Note: subsequent pages would be appended... eg:
https://example.com/ca/en/events/event-name/subpage/
You may be be able to use this single redirect rule on top of your .htaccess:
RewriteEngine On
RewriteRule ^([a-z]{2})/(.+)/([a-z]{2}/?)$ $1/$3/$2 [L]

Storing fish shell aliases in another file

I have a config.fish in ~/.config/fish. While editing my fish_prompt I accidentally deleted my aliases once. I did have backup, but I want to store all aliases separately from now on. Also, how can I auto-load all of my aliases when I source the newly-edited config.fish?
I have alias update="source ~/.config/fish/config.fish". So if I make change to the location of my config.fish and edit the alias as necessary, next time I update the updated alias should reflect in the updated config. How can I do this?
There are a few things fish offers here:
Files in ~/.config/fish/functions named after a function (plus a ".fish" ending) will be autoloaded once that function is called
Files in ~/.config/fish/conf.d/ (with a ".fish" ending) will be sourced before config.fish
So you can either put your functions/aliases in a function file each, or put them in files in conf.d in whatever grouping you want.
Also you can put your fish_prompt in its own file - ~/.config/fish/functions/fish_prompt.fish
(also "alias" is simply a cheesy helper function to make functions - the core shell has no concept of aliases)

Apache mod_rewrite path name as query parameters?

I want to use Apache's mod_rewrite in order to be able to take each folder of a path as a particular query parameter, for example consider the following:
Basic example
Url requested: http://domain.com/shoes/prada/image-1/
Page served: http://domain.com/?cid=shoes&bid=prada&pid=image-1
In this scenario, there are 3 sub-folders requested (/shoes/, /prada/ then image-1), so the first sub-folder is passed in the actual page served as cid, the second as bid and the third as pid.
Full example
However, I would also like it to serve a particular page depending on the number of sub-folders requested, e.g.
Url requested: http://domain.com/shoes/prada/
Page served: http://domain.com/shop.php?cid=shoes&bid=prada
So far all I've managed to find is regex based matching for mod_rewrite but my path's will vary a lot, which is why I would like to have conditions based on the number of folders accessed (please note, I'm not that good with regex - I reckon a wildcard character would help with this, but I wouldn't be sure where to start).
Any help on this would be greatly appreciated! This is pretty long winded, so if you need any more info for clarifying, please let me know!
With a little bit of work I was able to tweak some regex and get a working rule set for what I wanted:
RewriteEngine on
RewriteRule ^(.*)/(.*)/(.*)/(.)?$ product.php?tid=$1&sid=$2&eid=$3 [L]
RewriteRule ^(.*)/(.*)/(.)?$ brand.php?tid=$1&sid=$2 [L]
RewriteRule ^(.*)/(.)?$ shop.php?tid=$1 [L]
This is a bit different to the example, however it's what I intended for in the first place.
This allows for the rewriting of url's up to four folders deep, with the "name" of each folder being given as a parameter, and each additional level of depth rewriting the url to a separate resource for example:
http://x.com/shoes/prada/2011-high-heels/ -> http://x.com/product.php?tid=shoes&sid=prada&eid=2011-high-heels
Tested on http://martinmelin.se/rewrite-rule-tester/

Apache rule to change / (slash) to _ (underscore)

I've set up an Apache HTTP server with VirtualHosts in front of a proprietary web server in the back. The backend server can only have one (1) level in its ID paths so the following public URLs:
http://public-server/path1/path2/path3?querystring-parameters
should be converted for the backend to:
http://internal-server/path1/path2/page/<path1>_<path2>_<path3>?querystring-parameters
Notice that there can be any number of path1, path2, path3, path4, .... and they should all (no matter if only 1 exists or multiple) be concatenated with an underscore. Also notice that the querystring-parameters CAN contain '?', '/' and '_' so the rule should not alter the querystring in any way.
I've tried searching for solutions to this but can't figure out how to overcome the problem. Any suggestions?
If you can come up some maximum number of possible paths, you can do something to this effect:
# This will work for up to 5 paths
RewriteRule /([^/]*)/?([^/]*)/?([^/]*)/?([^/]*)/?([^/]*) http://internal-server%{REQUEST_URI}$1_$2_$3_$4_$5 [L,QSA]
The /?([^/]*) can be added to the end as many times as you need, along with added the corresponding groups (_$6 ..) to the rewritten URL.
Unfortunately, there is not a way have a completely unknown number of paths, while at the same time use them in the rewritten URL. Also, the [QSA] flag will attach your querystring on to the forwarded URL, untouched.
Hope this helps.